Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - How do I limit subfolder recursion?

Reply
 
Old 02-05-2009   #1 (permalink)
Larry


 
 

How do I limit subfolder recursion?

I want to enumerate the subfolders of a root folder and the subfolders
subfolders but I don't want to walk all the way down to the end of the folder
path. How can I set the number of recursions?

I've experimented with some "For counter = start to end" statements but I'm
just not getting the desired result.

My System SpecsSystem Spec
Old 02-05-2009   #2 (permalink)
ekkehard.horner


 
 

Re: How do I limit subfolder recursion?

Larry schrieb:
Quote:

> I want to enumerate the subfolders of a root folder and the subfolders
> subfolders but I don't want to walk all the way down to the end of the folder
> path. How can I set the number of recursions?
>
> I've experimented with some "For counter = start to end" statements but I'm
> just not getting the desired result.
You'll have to pass the relevant information (current level, maximum
level) thru the recursive process. Using parameters seem the easiest way:

Option Explicit

Dim goFS : Set goFS = CreateObject( "Scripting.FileSystemObject" )

Dim nRes
nRes = Tree00( goFS.GetFolder( "..\zapme" ), 4, 0 )
WScript.Echo
nRes = Tree00( goFS.GetFolder( "..\zapme" ), 2, 0 )
WScript.Quit 0

Function Tree00( oDir, nMxLevel, nLevel )
Dim nRVal : nRVal = 0 ' assume no error
WScript.Echo nLevel, Space( nLevel ), oDir.Path

If nLevel < nMxLevel Then
Dim oItem
For Each oItem In oDir.SubFolders
nRVal = Tree00( oItem, nMxLevel, nLevel + 1 )
Next
End If

Tree00 = nRVal
End Function
My System SpecsSystem Spec
Old 02-05-2009   #3 (permalink)
Richard Mueller [MVP]


 
 

Re: How do I limit subfolder recursion?


"Larry" <Larry@xxxxxx> wrote in message
news:A039DBD9-2492-45B9-8C0F-30333B631F5B@xxxxxx
Quote:

>I want to enumerate the subfolders of a root folder and the subfolders
> subfolders but I don't want to walk all the way down to the end of the
> folder
> path. How can I set the number of recursions?
>
> I've experimented with some "For counter = start to end" statements but
> I'm
> just not getting the desired result.
Are you using the FileSystemObject or WMI? Can you briefly show the part of
your code that enumerates all folders from the root?

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 02-08-2009   #4 (permalink)
Larry


 
 

Re: How do I limit subfolder recursion?

I'm using the FSO. I gave up on the code so I don't have an example to show
you. Thanks for your time but Ekkehard.Horner cross-posted a great example
that I'm going to work with.

"Richard Mueller [MVP]" wrote:
Quote:

>
> "Larry" <Larry@xxxxxx> wrote in message
> news:A039DBD9-2492-45B9-8C0F-30333B631F5B@xxxxxx
Quote:

> >I want to enumerate the subfolders of a root folder and the subfolders
> > subfolders but I don't want to walk all the way down to the end of the
> > folder
> > path. How can I set the number of recursions?
> >
> > I've experimented with some "For counter = start to end" statements but
> > I'm
> > just not getting the desired result.
>
> Are you using the FileSystemObject or WMI? Can you briefly show the part of
> your code that enumerates all folders from the root?
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
>
>
My System SpecsSystem Spec
Old 02-08-2009   #5 (permalink)
Larry


 
 

Re: How do I limit subfolder recursion?

Thanks for the great example. It does just what I was looking for. I'm
breaking it down so that I fully understand it and can learn to script
better.

It looks like "nRVal" is a variable for recursion value. There are two parts
of the code that I don't understand. Lines 12 & 22:

"nRVal = 0 'assume no error" & "Tree00 = nRVal"

I commented them out and the code still works fine. What are the purposes of
those two lines?


"ekkehard.horner" wrote:
Quote:

> Larry schrieb:
Quote:

> > I want to enumerate the subfolders of a root folder and the subfolders
> > subfolders but I don't want to walk all the way down to the end of the folder
> > path. How can I set the number of recursions?
> >
> > I've experimented with some "For counter = start to end" statements but I'm
> > just not getting the desired result.
>
> You'll have to pass the relevant information (current level, maximum
> level) thru the recursive process. Using parameters seem the easiest way:
>
1> Option Explicit
2>
3> Dim goFS : Set goFS = CreateObject( "Scripting.FileSystemObject" )
4>
5> Dim nRes
6> nRes = Tree00( goFS.GetFolder( "..\zapme" ), 4, 0 )
7> WScript.Echo
8> nRes = Tree00( goFS.GetFolder( "..\zapme" ), 2, 0 )
9> WScript.Quit 0
10>
11> Function Tree00( oDir, nMxLevel, nLevel )
12> Dim nRVal : nRVal = 0 ' assume no error
13> WScript.Echo nLevel, Space( nLevel ), oDir.Path
14>
15> If nLevel < nMxLevel Then
16> Dim oItem
17> For Each oItem In oDir.SubFolders
18> nRVal = Tree00( oItem, nMxLevel, nLevel + 1 )
19> Next
20> End If
21>
22> Tree00 = nRVal
23> End Function
Quote:

>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
RE: file rename with folder recursion PowerShell
recursion help request VB Script
Xml, Recursion and Base64 PowerShell
Xml and Recursion PowerShell
Xml, recursion and Ôase64 PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46