How can I list all the folders in a directory with VBScript?
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
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
Here is a list of freeware that will output directory lists link if you don’t want to write the VB yourself.
@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.
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 
This question is in the General Section. Responses must be helpful and on-topic.