How to build a directory list

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
User avatar
JRL
Automation Wizard
Posts: 3529
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

How to build a directory list

Post by JRL » Tue Oct 18, 2005 1:49 pm

Hi,
I'm trying to speed up a file finding program. I'm searching through a network drive that has 1200 directories and 200,000 files and is growing daily. A simple DOS search (dir p:\filename.ext /s) can take up to five minutes. On the other hand, if I use DOS to create a directory list (dir p:\*.* /s /ad /b > c:\~PDrive~.txt), Then use Macro Scheduler to FindFile filename.ext reading each directory from the ~PDrive~.txt file, I can find any file in 3 seconds or less. The problem is it still takes 5 minutes to create the directory list.

I know very little (nothing) about VB Script and was hoping someone with experience could show mw how to create a VB Script that performs a recursive directory search and creates a list similar to the output of (dir *.* /ad /s /b).

I found one example in the forum:
http://www.mjtnet.com/forum/viewtopic.p ... folderlist

But it does not display any sub directories. Searching the internet, I've found many scripts for recursively finding a specific file. From my post it may sound like that is what I'm looking for but it is not. I want to compile a list of all the directories on a specified drive using VB Script.

Thanks for any advice,
Dick

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Tue Oct 18, 2005 10:08 pm

This may help:

Using DOS, do dir *. to get directories vs. dir *.* which gets all files.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
JRL
Automation Wizard
Posts: 3529
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Oct 18, 2005 10:37 pm

Thanks for the response Bob.

I remember doing dir *. to get directory names only, but that was 20 years ago. Even then it was inaccurate because directory names could have 3 character extensions. Back then I wrote a batch file that did a "find" for the column that had the " that preceded all directory names.

Today all you need is a "/AD" and a dir will only output directories. thus the line:

dir *.* /ad /s /b will provide output that is directory names only, including all subdirectories and in the "bare" format. "Bare" meaning only the names will be listed, date/time/size/etc will be excluded.

I appreciate your input.
Dick

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Wed Oct 19, 2005 2:42 am

Oops, I missed the /ad switch in your line, only saw the *.*.
Old habits go away slowly.........

And you are correct, /ad is more encompassing then *.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

User avatar
Monkster
Junior Coder
Posts: 42
Joined: Fri Oct 04, 2002 9:37 pm
Location: On an Island with Wilson

Post by Monkster » Wed Oct 19, 2005 12:03 pm

Hi Dick,
I think the following should work for what you are trying to do:


Let>VBS_TIMEOUT=20000
VBSTART

Sub GetAllSubFolders(foldername)
On Error Resume Next
Dim f, fc
Set f = fs.GetFolder(foldername)
Set fc = f.SubFolders
For Each f in fc
outf.WriteLine f.Path
GetAllSubFolders foldername & "\" & f.name
Next
End Sub

Dim fs, d, foldername
Set fs = CreateObject("Scripting.FileSystemObject")
Set outf = fs.OpenTextFile("C:\~PDrive~.txt", 2, True)

GetAllSubFolders "P:\"
outf.Close
Set fs = Nothing
Set outf = Nothing
MsgBox "All done"

VBEND

VBRUN>GetAllSubFolders



You will probably get a message indicating that the script is taking too long
to complete - ignore that and the error message will dismiss itself and
complete successfully. See the thread titled "VBScript time out
message
" for further background on the error message.

Edit:
used to read "GetAllSubFolders foldername+"\" & f.name"
changed to "GetAllSubFolders foldername & "\" & f.name"
works either way, but this is better syntax
Last edited by Monkster on Wed Oct 19, 2005 6:13 pm, edited 1 time in total.
Best Wishes,
Monkster

User avatar
JRL
Automation Wizard
Posts: 3529
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Oct 19, 2005 1:32 pm

Monkster,

Thank you very much. I hope to try it yet this morning.

I'll let you know how it goes,
Dick

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Wed Oct 19, 2005 2:27 pm

You can change the VBScript timeout by setting the VBS_TIMEOUT variable.
MJT Net Support
[email protected]

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts