Need GetDirList or GetFolderList

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
DLeger

Need GetDirList or GetFolderList

Post by DLeger » Thu Feb 12, 2004 4:50 pm

I need get a list of folder names within a folder much like GetFileList will get a list of files within a folder.

Any ideas? Thanks.

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 » Thu Feb 12, 2004 8:34 pm

DIR *. will provide a list of folders.
Run Program>command /c dir c:\myfolders\*. > c:\myfolders\folders.txt
should give a file with a list of the folders in c:\myfolders folder. Results will be in the file folders.txt in the myfolders folder.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

DLeger

Need GetFolderList

Post by DLeger » Fri Feb 13, 2004 3:19 pm

I found a solution but you need to use VBScript. Make sure that the script is placed before any code that uses it.

DLeger

VBSTART
Function GetFolderList(folderspec)
Dim fso, f, f1, fc, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fc = f.SubFolders
For Each f1 in fc
s = s & f1.name
s = s & ";"
Next
GetFolderList = s
End Function
VBEND

let>myDir=C:\Whatever
VBEVAL>GetFolderList("%myDir%"),folderList
Separate>folderList,;,folders
let>count=folders_count-1
MessageModal>Num Folders: %count%

Let>k=0
Repeat>k
Let>k=k+1
MessageModal>folders_%k%
Until>k,count

rullbandspelare
Pro Scripter
Posts: 149
Joined: Tue Mar 23, 2004 9:11 pm

Post by rullbandspelare » Tue Apr 13, 2004 8:41 am

Hi!
I too need a GetDirList function.
I have tried both suggested solutions, but they dont help very much.
The first gives a lot of text that makes it hard to separate the Dir names.
And the second dont work at all for me. I get a VB compilation error.

Any other ideas or solutions on how to get the names of the directorys?

Thanks!
Tomas

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 Apr 13, 2004 10:09 pm

The first gives a lot of text that makes it hard to separate the Dir names.
Let's go back to:
Posted: Thu Feb 12, 2004 4:34 pm
Post subject: DIR *. will provide a list of folders.

Run Program>command /c dir c:\myfolders\*. > c:\myfolders\folders.txt
should give a file with a list of the folders in c:\myfolders folder. Results will be in the file folders.txt in the myfolders folder.
I was just trying to give you the basic tool to get the information. More steps need to be taken to make it more legible.

From the folders.txt file, make a loop to read the file, use MidStr to capture the first 20 characters of the lines starting with line 8. Send results to a file. If line does not include then end process. Open the file and you have your list of directories.

Start the total script with an Input> prompt for the beginning directory, and you will have a generic Directory List tool. Input has a built in Browse button and the ability to have a default.

The power of Macro Scheduler is that this can be a one-keystroke solution,
but you will have to write some code to make it happen.

Rough outline of script:
Input>
Run Program> dir *. \s > folders.txt
Start Loop
Read lines in folders.txt
Skip First 7 lines
Read first 20 characters and append to a file: DirList.txt
Go to next line and repeat loop until line does not inlcude
End loop
Open DirList.txt
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

rullbandspelare
Pro Scripter
Posts: 149
Joined: Tue Mar 23, 2004 9:11 pm

Post by rullbandspelare » Wed Apr 14, 2004 2:20 pm

Hi!
Thanks!
Do You know what!

in Windows XP i found that
dir /B *.
gives a clean list of directorys, no extra info - just a lits of directorys!

:D

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 Apr 14, 2004 3:36 pm

Aargh!...Also in Win98SE and Win98ME. :oops:
Never saw that switch slip in. I know it wasn't there with DOS 1.2 the last time I looked. :lol:

It also works with /s to show full path of sub directories
dir *. /s /b

Thanks for the refresher course rullbandspelare
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

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