![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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. 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 Specs![]() |
| | #3 (permalink) |
| | 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. your code that enumerates all folders from the root? -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #4 (permalink) |
| | 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 Specs![]() |
| | #5 (permalink) |
| | 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: > 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 Specs![]() |
![]() |
| 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 | |||