0

I'm using FileSystemObject to loop from files in folder, but I found that in some cases I'm missing files.

I have a folder with 20 files and when trying to list them I only see 14. The path is very long, so it seems to skip the files with >250 characters long.

Sub CountFilesInFolder()
   
    Dim xFileSystemObject As Object
    Dim xFolder As Object
    Dim xFile As Object
    Dim countx As Long
    Dim xFolderName As String
    Dim rowIndex As Long
    
    xFolderName = "\\server\[long folder name]"
     
    Set xFileSystemObject = CreateObject("Scripting.FileSystemObject")
    Set xFolder = xFileSystemObject.GetFolder(xFolderName)
    
    For Each xFile In xFolder.Files
        rowIndex = rowIndex + 1
        Application.ActiveSheet.Cells(rowIndex, 1).Formula = xFile.Name
    Next
    
End Sub

Is there any other way to extract the list of files (and information from the files) using vba?

I tried both methods from another question here, but I got the same problem

Selrac
  • 2,203
  • 9
  • 41
  • 84
  • Some of the solutions on [this post](https://stackoverflow.com/q/2516702/6706419) may be of interest – urdearboy Dec 15 '20 at 18:05
  • 3
    Does this answer your question? [Access files with long paths (over 260)](https://stackoverflow.com/questions/38432250/access-files-with-long-paths-over-260) – HackSlash Dec 15 '20 at 18:27

1 Answers1

0
'use short name instead and check if all your files are listed

xFile.ShortName