Re: Folder enumeration
- From: "mayayana" <mayaXXyana1a@xxxxxxxxxxxxxxxx>
- Date: Thu, 04 Jan 2007 14:41:29 GMT
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?
.
- Follow-Ups:
- Re: Folder enumeration
- From: scriptnovice
- Re: Folder enumeration
- From: scriptnovice
- Re: Folder enumeration
- References:
- Folder enumeration
- From: scriptnovice
- Folder enumeration
- Prev by Date: Re: showModalDialog
- Next by Date: Re: How to use ie autologon need identity authentiction IIS by VBscript?
- Previous by thread: Folder enumeration
- Next by thread: Re: Folder enumeration
- Index(es):
Relevant Pages
|
Loading