Access files with long paths (over 260)

calendar_today Asked Jul 18, 2016
thumb_up 6 upvotes
history Updated April 14, 2026

Direct Answer

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…. This is a 3-line VBA Core snippet, ranked #70th of 95 by community upvote score, from 2016.


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.

help
Frequently Asked Questions

This is a below-median answer — when does it still fit?
expand_more

Answer score +6 vs the VBA Core archive median ~4; this entry is niche. The score plus 7 supporting upvotes on the question itself (+7) means the asker and 5 subsequent voters all validated the approach.

Does the 3-line snippet run as-is in Office 2026?
expand_more

Yes. The 3-line pattern compiles on Office 365, Office 2024, and Office LTSC 2026. Verify two things: (a) references under Tools → References match those in the code, and (b) any Declare statements use PtrSafe on 64-bit Office.

Published around 2016 — what’s changed since?
expand_more

Published 2016, which is 10 year(s) before today’s Office 2026 build. The VBA Core object model has had no breaking changes in that window. Three things to re-test: (1) blocked macros on downloaded files (Mark-of-the-Web), (2) 64-bit API declarations (PtrSafe, LongPtr), (3) any shift toward Office Scripts for web scenarios.

Which VBA Core pattern ranks just above this one at #69?
expand_more

The pattern one rank above is “Run VBA script from R”. If your use case overlaps, compare both before committing.

Data source: Community-verified Q&A snapshot. Q-score 7, Answer-score 6, original post 2016, ranked #70th of 95 in the VBA Core archive. Last regenerated April 14, 2026.

vba