General Question

erichw1504's avatar

How can I list all the folders in a directory with VBScript?

Asked by erichw1504 (26453points) August 26th, 2009

I just need to list all the folders that exist in a certain directory. Just the folder’s name. I’ve searched Google and Yahoo! but wasn’t much help. Also, I would like for it to dump the names into a text file or something.

Observing members: 0 Composing members: 0

4 Answers

hex's avatar

Haven’t tried this, but should work using the .Subfolders method:

Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set objFolder = objFSO.GetFolder(“C:\”)
Set colSubfolders = objFolder.Subfolders

For Each objSubfolder in colSubfolders
Wscript.Echo objSubfolder.Name, objSubfolder.Size
Next

PerryDolia's avatar

Here is a list of freeware that will output directory lists link if you don’t want to write the VB yourself.

erichw1504's avatar

@hex Thanks! I had something similar but it would output the whole location of each folder. The only thing I change with your script was removing the objSubfolder.Size. It didn’t like it there for some reason.

hex's avatar

No problem, may not have like the .Size call because it is a numeric output function and .Name is string. .Echo likes to have everything output to string. If you really want the .Size you can just convert the numeric to a string.

Answer this question

Login

or

Join

to answer.

This question is in the General Section. Responses must be helpful and on-topic.

Your answer will be saved while you login or join.

Have a question? Ask Fluther!

What do you know more about?
or
Knowledge Networking @ Fluther