|
-
Aug 29th, 2007, 04:53 PM
#4
Re: Directory Searching
how long does it take to do a similar search in windows explorer?
the other method that would be simple to code is to use the file system object then you would not need to iterate through all the files, just work with the collections
i haven't tried to do this, but it would be worth testing, often the search would take as long, but in this case it may be quicker, you would need to add a reference to microsoft scripting runtime
Code:
Sub dirs(startpath, pattern)
Dim fs As New FileSystemObject, sf As Object, dirarr() As String, cnt As Long
ReDim dirarr(100)
For Each sf In fs.GetFolder(startpath).SubFolders
dirarr(cnt) = sf.Path
cnt = cnt + 1
If LCase(sf.Name) Like LCase(pattern) Then
If Not Len(foundarr(0)) = 0 Then ReDim Preserve foundarr(UBound(foundarr) + 1)
foundarr(UBound(foundarr)) = sf.Path
End If
Next
If Not cnt = 0 Then
ReDim Preserve dirarr(cnt - 1)
For i = 0 To UBound(dirarr)
dirs dirarr(i), pattern
Next
End If
End Sub
Sub finddir()
ReDim foundarr(0)
dirs "C:\Documents and Settings\peter\My Documents", "my*"
End Sub
try some speed test with this
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|