Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Faster alternative to Dir() ?
I have a program that requires parsing a very large directory structure,
and although the Dir() function is MUCH better than using the scripting.filesystemobject for iterating over file paths, I was wondering if there is an even faster alternative, perhaps API calls. All I need to be able to do is to recursively enumerate all file paths within a directory. I am doing this from Excel 2002 VBA. Any help would be most appreciated. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Faster alternative to Dir() ?
I have found API functions to iterate over files on the following site:
http://support.microsoft.com/default...b;en-us;185476 However, these API functions are significantly slower than using Dir(). The exact functions I used are at the bottom. I iterated over a particular directory 20 times each. These API functions are not what I am looking for: are there any other possibilities? These are my results: API 0.746 seconds elapsed. GetFileListArray 0.035 seconds elapsed. Function FindFilesAPI(ByVal Path As String, Optional ByVal SearchStr As String = "*") As String() Dim FileName As String ' Walking filename variable... Dim fileNames() As String ' Buffer for directory name entries Dim nFile As Integer ' Number of directories in this path Dim hSearch As Long ' Search Handle Dim WFD As WIN32_FIND_DATA Dim Cont As Integer If Right(Path, 1) < "\" Then Path = Path & "\" ' Walk through this directory and sum file sizes. hSearch = FindFirstFile(Path & SearchStr, WFD) Cont = True If hSearch < INVALID_HANDLE_VALUE Then While Cont FileName = StripNulls(WFD.cFileName) If (FileName < ".") And (FileName < "..") And _ ((GetFileAttributes(Path & FileName) And _ FILE_ATTRIBUTE_DIRECTORY) < FILE_ATTRIBUTE_DIRECTORY) Then ReDim Preserve fileNames(nFile) fileNames(nFile) = FileName nFile = nFile + 1 End If Cont = FindNextFile(hSearch, WFD) ' Get next file Wend Cont = FindClose(hSearch) End If FindFilesAPI = fileNames End Function Public Function GetFileListArray(ByVal Path As String, Optional ByVal Filter As String = "*") As String() Dim DirectoryFiles() As String Dim strFileName As String strFileName = Dir(Path & Filter) Do While strFileName < "" If strFileName < "" Then ReDim Preserve DirectoryFiles(Count) DirectoryFiles(Count) = strFileName Count = Count + 1 End If strFileName = Dir() Loop GetFileListArray = DirectoryFiles End Function |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
can this be done faster? | Excel Discussion (Misc queries) | |||
Which is faster? SUMPRODUCT or VLOOKUP, or another alternative? | Excel Worksheet Functions | |||
Which method is faster | Excel Discussion (Misc queries) | |||
Can faster CPU+larger/faster RAM significantly speed up recalulati | Excel Discussion (Misc queries) | |||
Which one is faster? | Excel Programming |