Here’s the second script of today.
It is a mutation of the previous script.
Added is a depth limit, this is done by a second argument of the subroutine.
The subroutine needs two arguments: the path of the folder and the depth level.
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
- change the depth value to your depth value (current value = 2)
- save the script (for example c:tempenumeratesubfolderslevel.vbs)
- open a command prompt
- go to “c:temp”
- give “cscript enumeratesubfolderslevel.vbs” (without quotes) and enter
The script:
' Name : enumeratesubfolderslevel.vbs
' Description : script to enumerate the subfolders (recursive) with depth limit
' Author : dirk adamsky - deludi bv
' Version : 1.01 corrected small counter error
' Date : 05-03-2010
' Level : Intermediate
ViewSubFolders "c:temp", 2
Sub ViewSubFolders(strFolder, strMaxLevel)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strFolder)
If strMaxlevel >= 1 Then
For Each SubFolder in objFolder.SubFolders
Wscript.Echo SubFolder.Path
ViewSubFolders SubFolder, (strMaxlevel - 1)
Next
End If
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="2" banner="3"]
