Message 1 of 6
Get list of files/folders *fast*
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I'm using a recursive sub to get list of files within a folder (on a network server), using FileSystemObject. It is terribly slow. On a folder ocntaining 100-150 subfolders and maybe 5-6000 files, it takes a minute or two.
I have ported the exact same code to vb.net and using FileIO.Filesystem calls, which is waaaaaaaay faster, taking about a second.
Why is it so slow from Inventor VBA? And what is the fastest way to get such a filelist?
I've tried using default VBA file commands but they have problems with UTF8 filenames, so it's not usable.
code I'm using:
Public Sub GetFileList(ByRef Fcoll As Collection, ByVal CurrentFolder As String, ByVal Mask As String, ByVal Recursive As Boolean, Optional ByRef ExcludedFolders As Variant)
Dim Excluded As Boolean
Excluded = False
If Not IsError(ExcludedFolders) Then
For Each Item In ExcludedFolders
If InStr(CurrentFolder, Item) <> 0 Then Excluded = True
Next
End If
If Excluded = False Then
For Each File In ThisApplication.FileManager.FileSystemObject.GetFolder(CurrentFolder).Files
For Each Item In Split(Mask, "|")
If File.Name Like Item Then Fcoll.Add File.Path
Next
Next
If Recursive Then
For Each Folder In ThisApplication.FileManager.FileSystemObject.GetFolder(CurrentFolder).SubFolders
Call GetFileList(Fcoll, Folder.Path, Mask, Recursive, ExcludedFolders)
Next
End If
End If
End Sub
vb.net:
Public Sub GetFileList(ByRef FColl As Collection, ByVal CurrentFolder As String, ByVal Mask As String, ByVal Recursive As Boolean, Optional ByRef ExcludedFolders As Object = Nothing)
Dim Excluded As Boolean
Excluded = False
If Not IsNothing(ExcludedFolders) Then
For Each Item In ExcludedFolders
If Strings.InStr(CurrentFolder, Item) <> 0 Then Excluded = True
Next
End If
If Excluded = False Then
For Each File In FileIO.FileSystem.GetFiles(CurrentFolder)
For Each Item In Split(Mask, "|")
If FileIO.FileSystem.GetName(File) Like Item Then FColl.Add(File)
Next
Next
If Recursive Then
For Each Folder In FileIO.FileSystem.GetDirectories(CurrentFolder)
Call GetFileList(FColl, Folder, Mask, Recursive, ExcludedFolders)
Next
End If
End If
End Sub