So I tried to come up with some simple code in VBscript which recursively searches
a directory for file names of arbitrary patterns. This is what I got working:
Sub recursiveSearch(dir, regex)
for each file in dir.files
if regex.Test(file.Name) Then
WScript.Echo("File matches: " & file.Path)
End if
next
for each folder in dir.SubFolders
recursiveSearch folder, regex
next
End Sub
startFolder="c:\temp"
set folder=CreateObject("Scripting.FileSystemObject").GetFolder(startFolder)
Set regex=new RegExp
regex.Pattern = "^Foo\d{3}[0-9a-zA-Z]\.txt$"
' File name starts with 'Foo', followed by three digits, then either
' a digit or letter, and has a .txt extension.
recursiveSearch folder, regex
Somehow I've got a hunch that there may be an easier way to do this. Blogosphere, any ideas?
to top