Hi,
I'm trying to list Excel files within whose filenames DON'T meet certain criteria. I'm using a recursive process:
This works, but is horrendously slow. I think I'm probably barking up the wrong tree and that there is a simpler and quicker way to go. FYI, the folder I'm interested in contains ~25,000 .xls files %-). Can anyone help??
Thanks, Iain
I'm trying to list Excel files within whose filenames DON'T meet certain criteria. I'm using a recursive process:
Code:
Public Sub Loop_SubFolders(strFolder As String)
On Error Resume Next
'Uses recursion to examine file structure
'Starts at fldRoot, works through all subfolders under that folder
'Calls List_Files to output file list
Dim fldRoot As folder
Dim fld As folder
Dim fs As FileSystemObject
'Create a new filesystemobject container
Set fs = New FileSystemObject
'Set the folder to be examined
Set fldRoot = fs.GetFolder(strFolder)
'Loop through the subfolders under this folder
For Each fld In fldRoot.SubFolders
'List the files in the folder
Call List_Files(fld)
Debug.Print fld.Path
'Call the process again for easch folder in the subfolder
Loop_SubFolders fld
Next fld
End Sub
Code:
Public Sub List_Files(strListFolder As String)
'lists files in strListFolder that meet criteria to a text file
On Error Resume Next
Dim fs As FileSystemObject
Dim fl As File
Dim fld As folder
Dim objFL As Object
Dim objDoc As Document
Set fs = New FileSystemObject
Set fld = fs.GetFolder(strListFolder)
Open "C:\Spreadsheets.txt" For Append As #1
For Each fl In fld.Files
'Just interested in Spreadsheet files
If Right(fl.Name, 4) = ".xls" Then
'------------------------------------------
'Check against the list of names to exclude
'------------------------------------------
If fl.Name Like "*TextString1ToCheck*" Then
GoTo tagNextFor
ElseIf fl.Name Like "*TextString2ToCheck*" Then
GoTo tagNextFor
ElseIf etc, to string 23...
End If
'No match, output the file path
Print #1, fl.Path
End If
tagNextFor:
Next fl
Close #1
End Sub
This works, but is horrendously slow. I think I'm probably barking up the wrong tree and that there is a simpler and quicker way to go. FYI, the folder I'm interested in contains ~25,000 .xls files %-). Can anyone help??
Thanks, Iain