The Problem (Q-score 7, ranked #70th of 95 in the VBA Core archive)
The scenario as originally posted in 2016
I’m using Microsoft Scripting Runtime (FSO) to parse folders and produce a list of all of its contents, the folders are on a network and resultant paths end up longer than 260. The minimum code I have is as below:-
Private Sub ProcessFolder(ByVal StrFolder As String)
Dim Fl As File
Dim Fldr As Folder
Dim RootFldr As Folder
Set RootFldr = FS.GetFolder(StrFolder)
For Each Fl In RootFldr.Files
Debug.Print Fl.Path
Next
For Each Fldr In RootFldr.SubFolders
DoEvents
ProcessFolder Fldr.Path
Next
Set RootFldr = nothing
End sub
At a certain level StrFolder length became 259, the Set RootFldr ... folder line worked but For Each Fl In RootFldr.Files gave the error of 76: Path not found, presumably because the content causes the path to breach the 260 limit.
There were files in the folder when looking in Windows Explorer. I am using Excel as the host for this code as I’m outputting the result to workbooks.
Just to be super clear on my question and its background, I need to use FSO (happy to be shown alternatives if they exist) to access files deeper than 260 characters deep in their network path. I need it as FSO as the tool I have is taking the folder paths and the file paths, name, size created, and modified.
Why community consensus is tight on this one
Across 95 VBA Core entries in the archive, the accepted answer here holds niche answer (below median) status — meaning voters are unusually aligned on the right fix.
The Verified Solution — niche answer (below median) (+6)
3-line VBA Core pattern (copy-ready)
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:foobarbaz.txt - Prefix a path that uses a file share with
'\?UNC, like\?UNCserversharebaz.txt.
Works well with FileSystemObject too, at least when I tested your code on Windows 10. That might not necessarily be the case in older Windows versions or with the network redirector on your server. Tested by using the FAR file manager to create subdirectories with long names and verified with:
Dim path = "\?C:tempLongNameTest"
ProcessFolder path
Produced:
\?c:tempLongNameTestVeryLongFolderName0123456789012345678901234567890123456789012345678901234567890123456789VeryLongFolderName0123456789012345678901234567890123456789012345678901234567890123456789VeryLongFolderName0123456789012345678901234567890123456789012345678901234567890123456789VeryLongFolderName0123456789012345678901234567890123456789012345678901234567890123456789VeryLongFolderName0123456789012345678901234567890123456789012345678901234567890123456789Chrysanthemum.jpg
Which is 488 characters long. Things to keep in mind:
- Native path names must be full paths, they cannot be relative paths. In other words, they must always start with a drive letter or share name and start from the root of the drive/share.
- You get the native path name back, don’t forget to strip the prefix off again if you display it.
- Not tested but should fail, there is still a limitation on the the length of the filename itself (without the directory names), can’t be longer than 259 chars. Shouldn’t be a problem at all since the user can’t create them either.
When to Use It — classic (2013–2016)
Ranked #70th in its category — specialized fit
This pattern sits in the 95% tail relative to the top answer. Reach for it when your scenario closely matches the question title; otherwise browse the VBA Core archive for a higher-consensus alternative.
What changed between 2016 and 2026
The answer is 10 years old. The VBA Core object model has been stable across Office 2013, 2016, 2019, 2021, 365, and 2024/2026 LTSC, so the pattern still compiles. Changes that might affect you: 64-bit API declarations (use PtrSafe), blocked macros in downloaded files (Mark-of-the-Web), and the shift toward Office Scripts for web-first workflows.