Access files with long paths (over 260)

The technique to convert MAXFILE encumbered DOS path names to native OS path names is well established and documented. Summarizing: Prefix a path that uses a drive letter with \\?\, like \\?\C:\foo\bar\baz.txt Prefix a path that uses a file share with ‘\\?\UNC\, like \\?\UNC\server\share\baz.txt. Works well with FileSystemObject too, at least when I tested your … Read more

reading and writing a csv file using FileSystemObject

It certainly is. Basic syntax such as Set objFSO = CreateObject(“scripting.filesystemobject”) ‘create a csv file Set objTF = objFSO.createtextfile(“C:\test\myfile.csv”, True, False) ‘open an existing csv file with writing ability Set objTF = objFSO.OpenTextFile(“C:\test\myfile.csv”, 8) will create/open a CSV with FSO. The CSV can then be modified by writing to it While this is an Excel … Read more

Order of Files collection in FileSystemObject

Is it really too much code to sort? set fso = CreateObject(“Scripting.FileSystemObject”) Set outputLines = CreateObject(“System.Collections.ArrayList”) for each f in fso.GetFolder(“.”).files outputLines.Add f.Name next outputLines.Sort() ‘ 5 lines… For Each outputLine in outputLines set file = fso.GetFolder(“.”).files.item (outputLine&””) Wscript.Echo file.name ‘ TODO: your thing here Next

Loop Through All Subfolders Using VBA [duplicate]

Just a simple folder drill down. sub sample() Dim FileSystem As Object Dim HostFolder As String HostFolder = “C:\” Set FileSystem = CreateObject(“Scripting.FileSystemObject”) DoFolder FileSystem.GetFolder(HostFolder) end sub Sub DoFolder(Folder) Dim SubFolder For Each SubFolder In Folder.SubFolders DoFolder SubFolder Next Dim File For Each File In Folder.Files ‘ Operate on each file Next End Sub

How do I use FileSystemObject in VBA?

Within Excel you need to set a reference to the VB script run-time library. The relevant file is usually located at \Windows\System32\scrrun.dll To reference this file, load the Visual Basic Editor (ALT+F11) Select Tools > References from the drop-down menu A listbox of available references will be displayed Tick the check-box next to ‘Microsoft Scripting … Read more