Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

recursive dir$

Status
Not open for further replies.

silverspecv

Programmer
Joined
Oct 31, 2003
Messages
125
Location
US
How can I get dir$ to operate recursively? I have tried to do it using recursive subs, but the dir$ seems to be global or something, and it will never pick up where it left off when I come back "up". What gives?
 
Dir$ is not directly useful in recursive solutions. You need to program around this limitation, or use an alternative method for determining file and folder names that can be used recursively (eg the FileSystemObject). A number of examples of both approaches have been provided in this forum in the past. A keyword search should dig them out.
 
Dir$ has a single/global scope which causes problems in recursive operation. However, it can be used recursively if you play with it carefully. See thread222-609352 for a demonstration.

Or you can always go for FileSystemObject as strongm suggested.
 
Thanks guys. I'm at least glad to know that it is a known issue and I wasn't just doing it wrong. I did wind up using the filesystemobject which worked perfectly once I got used to it. The collection method was interesting though. I considered using dir$ and storing it in an array and use that for recursion, especially since I had the luxury of only having 1 directory deep, so I could just loop wouldn't even have to recurse, but I wouldn't have thought to do deep recursion by creating a collection inside the recursive function. Pretty slick.. as usual, there are a zillion ways to do it.. Thanks to you both
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top