Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


A loop in a Sub

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,57948
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> A loop in a Sub
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 A loop in a Sub - 3/14/2008 7:29:28 AM   
  justjim

 

Posts: 5
Score: 0
Joined: 3/11/2008
Status: offline
I am having trouble constructing a loop in this sub, or figuring out a way to do this. This is what I am trying to do. Inside the C:\Windows\Somefolder are a number of subfolders and the names of the subfolders are random, only  the file names are known (and there are way more than 2). Hence the  recurse.
The problem with the code below is that if the file named TEST.DLL is found the script ignores the TEST2.DLL file and ends out of the Sub. Of visa-versa. If the files are found in the same Subfolder, then there is no problem. But if the files are located in different Subfolders, then the sub ends.  I'm out of ideas, so any help would be greatly appreciated.

      
 
 
Post #: 1
 
 RE: A loop in a Sub - 3/15/2008 5:32:02 AM   
  dm_4ever


Posts: 2641
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Your script is only going one level deep...you need to call the sub for each subfolder if you want it to find more....

you could also write what you have now like this...



      

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to justjim)
 
 
Post #: 2
 
 RE: A loop in a Sub - 3/16/2008 11:35:20 AM   
  justjim

 

Posts: 5
Score: 0
Joined: 3/11/2008
Status: offline
Thanks for your suggestion. Your version is better written than mine.

quote:

Your script is only going one level deep...you need to call the sub for each subfolder if you want it to find more....


I only need it to go one level deep in C:\Windows\Somefolder. There are a number of Subfolders, but none of the Subfolders have Subfolders of their own, only files.

I was hoping to be able to do this without recalling the sub a number of times.

(in reply to dm_4ever)
 
 
Post #: 3
 
 RE: A loop in a Sub - 3/17/2008 12:23:23 AM   
  ebgreen


Posts: 4971
Score: 31
Joined: 7/12/2005
Status: offline
"I was hoping to be able to do this without recalling the sub a number of times. "

Why?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to justjim)
 
 
Post #: 4
 
 RE: A loop in a Sub - 3/17/2008 12:32:42 AM   
  justjim

 

Posts: 5
Score: 0
Joined: 3/11/2008
Status: offline
quote:

Why?


If there are 10 or 15 files in 10 random subfolders under C:\Windows\somefolder then that would require rewritting the sub 10 to 15 times

(in reply to ebgreen)
 
 
Post #: 5
 
 RE: A loop in a Sub - 3/17/2008 12:44:57 AM   
  ebgreen


Posts: 4971
Score: 31
Joined: 7/12/2005
Status: offline
Actually no it would not. That is the whole point to recursion. Search the forim for examples of recursion.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to justjim)
 
 
Post #: 6
 
 RE: A loop in a Sub - 3/17/2008 12:49:09 AM   
  justjim

 

Posts: 5
Score: 0
Joined: 3/11/2008
Status: offline
I thought my script was a recursion.

Thank you

I will keep looking

(in reply to ebgreen)
 
 
Post #: 7
 
 RE: A loop in a Sub - 3/17/2008 12:55:17 AM   
  ebgreen


Posts: 4971
Score: 31
Joined: 7/12/2005
Status: offline
Your code is an iteration. An iteration does exactly that, it iterates through the items in a collection. A recursion is an iteration that calls itself for some or all of the items in a collection. So in pseudo-code here is an example of folder recursion:


RecurseFolder RootFolderName

Sub RecurseFolder(strFolderName)
   Do something with the files in the folder
   For each sub-folder in the folder
        Call RecurseFolder Sub-Folder Name
   Next
End Sub


So what will happen is that this would do something to all the files in all the folders in a folder tree no matter how deep the tree goes.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to justjim)
 
 
Post #: 8
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> A loop in a Sub Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts