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
How to build a directory list
Moderators: JRL, Dorian (MJT support)
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
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
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
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
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
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
Monkster
You can change the VBScript timeout by setting the VBS_TIMEOUT variable.
MJT Net Support
[email protected]
[email protected]