Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
can this be done faster? Frank Excel Discussion (Misc queries) 7 August 9th 07 10:02 PM
Which is faster? SUMPRODUCT or VLOOKUP, or another alternative? SteveC Excel Worksheet Functions 6 May 26th 06 01:57 PM
Which method is faster matpoh Excel Discussion (Misc queries) 2 October 21st 05 03:12 PM
Can faster CPU+larger/faster RAM significantly speed up recalulati jmk_li Excel Discussion (Misc queries) 2 September 28th 05 10:24 AM
Which one is faster? Syed Zeeshan Haider[_4_] Excel Programming 14 December 4th 03 05:28 PM


All times are GMT +1. The time now is 03:41 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"