Iterating through folders and files with paths > 260 characters

BarryL

Well-known Member
Joined
Jan 20, 2014
Messages
1,436
Office Version
  1. 2019
Platform
  1. Windows
  2. MacOS
Hi All,

As per the title, I am having an issue with iterating through folders and files where the path exceeds the charater limits. Below is my code:

Code:
 Sub test()

Dim FileSystem As Object
Dim HostFolder As String


HostFolder = Sheet1.Range("F16").Value
If HostFolder = "" Then
MsgBox "No folder selected"
Exit Sub
End If






Set FileSystem = CreateObject("Scripting.FileSystemObject")
DoFolder FileSystem.GetFolder(HostFolder)


End Sub
Sub DoFolder(Folder As Scripting.Folder)
 
  Dim SubFolder As Scripting.Folder, folderStr As String


 
    For Each SubFolder In Folder.SubFolders
    
 
        Sheet1.Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1).Value = SubFolder.Path
        Sheet1.Range("B" & Range("B" & Rows.Count).End(xlUp).Row + 1).Value = SubFolder.DateLastModified
            DoFolder SubFolder
    Next
    
    Dim File As Scripting.File
    For Each File In Folder.Files
         Sheet1.Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1).Value = File.Path
        Sheet1.Range("B" & Range("B" & Rows.Count).End(xlUp).Row + 1).Value = File.DateLastModified
    Next


End Sub

The code runs fine for me because I have my drives mapped, but the person I am sending it to cannot map their drives appropriately, so I am wondering is there a way around the character limit?

the error I am getting is "path not found" on the below line:
Code:
    For Each SubFolder In Folder.SubFolders

the subfolder path has exceeded the character limit and is now equal to "Nothing" in the locals window.

Does anyone know a way around this that doesn't include mapping? Also, is it possible to get the "Author" using FSO or can that only be done from shell?
 
Last edited:

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Forum statistics

Threads
1,223,888
Messages
6,175,207
Members
452,618
Latest member
Tam84

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top