Link to home
Start Free TrialLog in
Avatar of gabrielaz
gabrielaz

asked on

vbscript to list folder names

hello experts,
 looking for a script htat will list all folders in a directory... example
\\server\users.  so i would like all the folders names withing the users directory and list that to
notepad or excel.  thanks in advance.
ASKER CERTIFIED SOLUTION
Avatar of sirbounty
sirbounty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gabrielaz
gabrielaz

ASKER

thanks for the fast response.. it works great. i am new to scripting and i was hoping you explain the way the script works to me like what this stuff does.
First it creates a reference to the files system:
Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")

Using that , sets another object object to a report file for output info
Dim objOutput: Set objOutput = objFSO.CreateTextFile("C:\Folders.txt")

Establish a variable for the folder
fld="C:\ParentPath\"

run the sub, passing an object reference to that folder
EnumFolders (objFSO.GetFolder(fld))

'Once the sub is finished, close the file and destroy references..
objOutput.Close
Set objOutput=Nothing
Set objFSO = Nothing
wscript.quit

Sub EnumFolders(objFld)
'The next line writes the path of the folder to the output file
    objOutput.WriteLine objFld.Path
The next section loops through all subfolders, restarting the sub for each found
    For Each fld In objFld.SubFolders
        EnumFolders (objFSO.GetFolder(fld))
    Next
End Sub

Glad it worked for you. :^ )
Thank you.