FileSearch equivalent for *subfolder* search

M

Mark Tangard

Hi gang. I'm aware that the FileSearch object was scuttled in Office
2007, and I know how to use Dir$ to work around that, for searches in a
single folder. But can I use Dir$ to operate on files in all
*subfolders* (that is, to do what .SearchSubfolders=True used to do?
There must be a way, but I can't get my head around it. After much
Googling I found only one question asking about this, and no reply had
been posted. Help??

MT
 
G

GeoffG

You need to write a recursive procedure, i.e. a procedure that
calls itself. You pass appropriate arguments to the call so that
the subprocedure can continually call itself looking for
subfolders until it runs out of subfolders. Here is an example:

http://msdn.microsoft.com/en-us/library/aa164475.aspx

The above example uses the FileSystemObject. You will need to
set a reference to "Microsoft Scripting Runtime" (in the VBA
editor: Tools > References). This makes a Dictionary object
available, where you can store all the folders and subfolders.

The Microsoft website has another example that stores the folders
in a Rich TextBox, here:

http://support.microsoft.com/kb/189631

You could use Dir in a recursive subprocedure. You'd need to
take care of where to store the results.

Geoff
 
M

Mark Tangard

Thanks a ton, Geoff. I'm so rusty on recursion it never even occurred to me.

MT
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top