wlevy
asked on
VBScript retrieve filenames using wildcard
Is there a way in VBScript to retrieve a list of the files in a folder using wildcards?
My script uses the FileSystemObject (fso.GetFolder) but this returns all files in the specified folder.
There are at least a thousand files in the folder but I want to retrieve a subset, similar to DIR AP*.xml.
My kludgy solution is to test each filename ... IF Left(strFilename,2) = "AP" ... but as I have to test so many files this is unacceptably slow. Note that I am retrieving the folder contents from a mapped drive on a remote server.
My script uses the FileSystemObject (fso.GetFolder) but this returns all files in the specified folder.
There are at least a thousand files in the folder but I want to retrieve a subset, similar to DIR AP*.xml.
My kludgy solution is to test each filename ... IF Left(strFilename,2) = "AP" ... but as I have to test so many files this is unacceptably slow. Note that I am retrieving the folder contents from a mapped drive on a remote server.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Did that not work for you? I noticed you graded this a "B", just curious what could have been added to warrant an "A"?
ASKER
By adding more conditions to the WHERE clause I was able to filter the list to include only files in a specific folder that start with "AP" and have an extension of xml. This runs MUCH faster than using FileSystemObject.
Note that if listing a very large number of files where you want most of them, FileSystemObject is faster.
Thanks for your help!
Note that if listing a very large number of files where you want most of them, FileSystemObject is faster.
Thanks for your help!
ASKER
Sorry, perhaps I graded too harshly. I gave a grade of "B" because I had to do a lot of research and experimenting to satisfy all of my requirements (drive, path, filename wildcard, extension).