Re: Folder enumeration



One simple method would be to use a global
variable to count your recursions. Something
like:

Dim iDepth '-- declare global variable.

sPath = "C:\Windows\System"
iDepth = 0 '-- reset variable counter.
ShowSubFolders sPath, 3


Sub ShowSubFolders(Folder, Depth)
if iDepth = Depth then exit sub '-- quit when depth is reached.

'-- do recursion here ....

iDepth = iDepth + 1 '-- add one to recursion counter.
ShowSubFolders(Folder, Depth) '-- call next loop:

End Sub

Hi

I am trying to write a script to enumerate folders that will allow me
to specify how far down the folder structure I want the script to go.

I have code that will alow me to enumerate all the subfolders of a
given folder e.g.

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("C:\Scripts")
Set colSubfolders = objFolder.Subfolders
For Each objSubfolder in colSubfolders
Wscript.Echo objSubfolder.path
Next



and I have code which will allow me to loop through all the subfolders
of an entire folder structure e.g.

Set FSO = CreateObject("Scripting.FileSystemObject")
ShowSubfolders FSO.GetFolder("C:\Scripts")
Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
Wscript.Echo Subfolder.Path
ShowSubFolders Subfolder
Next
End Sub



Say for example my folder structure is as follows:

C:\Folder\A-SubFolder\A-SubFolder-1\A-SubFolder-2
C:\Folder\B-SubFolder\B-SubFolder-1\B-SubFolder-2

I want my script to loop through displaying the structure only as far
as A-SubFolder -1 and B-SubSFolder-1. I would like the output of my
script to look like the following:

C:\Folder
C:\Folder\A-SubFolder
C:\Folder\A-SubFolder\A-SubFolder-1
C:\Folder\B-SubFolder
C:\Folder\B-SubFolder\B-SubFolder-1

I want to be able to change how far down my folder structure the script
traverse before I run the script.

Can anyone help?



.



Relevant Pages

  • Folder enumeration
    ... I am trying to write a script to enumerate folders that will allow me ... to specify how far down the folder structure I want the script to go. ... and I have code which will allow me to loop through all the subfolders ...
    (microsoft.public.scripting.vbscript)
  • Clean out old files from multiple subfolders
    ... Does anyone have or would be able to write a script that would ... go through a big folder structure, and only when it finds certain subfolders, ...
    (microsoft.public.scripting.vbscript)
  • Re: Replicate 2005 folder structure for 2006 (subdirectories without files)
    ... No need for a script. ... > Now it is 2006 and someone has to replicate the folder structure .. ... > The department manager doesn't want to do it and neither do I. ... > Whiz Dunbar ...
    (microsoft.public.scripting.vbscript)
  • Re: Duplicate folder tree
    ... I just need to recreate the folder structure of the source ... > selected files and don't delete any folder from the source path. ... > Otherwise I will check the script because it's so interesting and I ...
    (microsoft.public.scripting.wsh)
  • Re: Duplicate folder tree
    ... I just need to recreate the folder structure of the source ... selected files and don't delete any folder from the source path. ... Otherwise I will check the script because it's so interesting and I ...
    (microsoft.public.scripting.wsh)

Loading