The motto of the day is: Recursion rules.
A couple of years ago I have done quite a few Filesystem Object scripts.
To refresh my mind I have made some new filesystem scripts.
This is the first one: a simple subroutine that uses recursion to enumrate all subfolders of a folder.
The subroutine needs one argument: the path of the folder.
The path can be local (“c:temp”) or an UNC path like “\servertest”.
Follow the next steps to run the script (admin rights needed on the folder you want to enumerate):
- open your favorite text editor
- copy and paste the script into the editor
- change the path of the folder to your folder path
- save the script (for example c:tempenumeratesubfolders.vbs)
- open a command prompt
- go to “c:temp”
- give “cscript enumeratesubfolders.vbs” (without quotes) and enter
The script:
' Name : enumeratesubfolders.vbs
' Description : script to enumerate all subfolders (recursive) of a given folder
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 05-03-2010
' Level : Intermediate
ViewSubFolders "c:temp"
Sub ViewSubFolders(strFolder)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strFolder)
For Each SubFolder in objFolder.SubFolders
Wscript.Echo SubFolder.Path
ViewSubFolders SubFolder
Next
Set objFolder = Nothing
Set objFSO = Nothing
End Sub
When you have problems/questions please make a reply, when you like the script please rate it with the star rating below.
Happy scripting.
Best regards,
Dirk Adamsky – Deludi BV
[adrotate group="3"]

[...] Filesystem: VBscript to enumerate all subfolders (recursive) of a given folder [...]