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 “\\server\test”.

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:\temp\enumeratesubfolderslevel.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

VN:F [1.9.3_1094]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.3_1094]
Rating: 0 (from 0 votes)
Like this Post? Consider sharing it on one of these:
  • Digg
  • LinkedIn
  • Slashdot
  • Technorati
  • RSS

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Spam Protection by WP-SpamFree Plugin

© 2010 Dirk Adamsky Scripting Blog Suffusion WordPress theme by Sayontan Sinha