Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Working With Subfolders

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Working With Subfolders
  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 >>
 Working With Subfolders - 5/12/2006 7:03:17 AM   
  who10

 

Posts: 33
Score: 0
Joined: 4/29/2006
Status: offline
I've got the code below to move a files from one folder to another folder based on the condition that the first 4 characters of the filename are "Test". 
Here's where I'm hung up.  I want to do the same thing, only the folder I want to move from is a subfolder and the subfolder name will change.  I would like to search through all the subfolders of a folder and look for the files where this condition exists, then copy them to a location.  Using this code, I'm not sure how to do that. 


      
 
 
Post #: 1
 
 RE: Working With Subfolders - 5/12/2006 7:04:48 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: online
Search these fora for "Recursion" and you will find plenty of examples of doing something for all of the files in all of the subfolders of a folder.

_____________________________

"... 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 who10)
 
 
Post #: 2
 
 RE: Working With Subfolders - 5/12/2006 2:30:16 PM   
  who10

 

Posts: 33
Score: 0
Joined: 4/29/2006
Status: offline
Well, I searched for "Recursion" and found quite a few examples.  I chose this one, but I'm still unable to  search through all the subfolders of a folder and look for the files where this condition exists.  This script will run without errors, but it will only find the files within the top folder.  It will not look for the condition within the subfolders.  Any tips?  Thanks.


      

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: Working With Subfolders - 5/13/2006 1:27:01 PM   
  who10

 

Posts: 33
Score: 0
Joined: 4/29/2006
Status: offline
Did some more searching, played around with it and this will actually get me what I need.  Not sure if it's the best way to do it, but it works.  Thanks.

      

(in reply to who10)
 
 
Post #: 4
 
 RE: Working With Subfolders - 5/15/2006 1:17:39 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: online
That is a perfectly good solution. I glad that you found what you needed and hopefully the experience of figuring it out for yourself was worth any associated pain. 

_____________________________

"... 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 who10)
 
 
Post #: 5
 
 RE: Working With Subfolders - 5/15/2006 7:45:39 AM   
  who10

 

Posts: 33
Score: 0
Joined: 4/29/2006
Status: offline
Yes, the experience is well worth it.
Thanks

(in reply to ebgreen)
 
 
Post #: 6
 
 RE: Working With Subfolders - 5/20/2006 2:23:29 PM   
  who10

 

Posts: 33
Score: 0
Joined: 4/29/2006
Status: offline
I've been trying to figure out how to count files found in a recursive search and I'm not getting the results I want.  When using the following search, each time a file is found, a number is echoed to the cmd window.  I'm looking for a way to echo the total to the command window.  For example, instead of:
1
1
1
1

I'd rather see:
4

Here's the code I'm using to test with.
Thanks.

      

(in reply to ebgreen)
 
 
Post #: 7
 
 RE: Working With Subfolders - 5/21/2006 8:00:22 AM   
  dalemontgomery45177

 

Posts: 26
Score: 0
Joined: 5/11/2006
Status: offline
 Move your 'count = 0' prior to the 'Sub showSubs(folder)' line

(in reply to who10)
 
 
Post #: 8
 
 RE: Working With Subfolders - 5/21/2006 2:59:42 PM   
  who10

 

Posts: 33
Score: 0
Joined: 4/29/2006
Status: offline
Thanks.  actually, I got what I want by echoing outside of the sub like so.

      

(in reply to dalemontgomery45177)
 
 
Post #: 9
 
 RE: Working With Subfolders - 6/6/2006 12:41:08 PM   
  who10

 

Posts: 33
Score: 0
Joined: 4/29/2006
Status: offline
Based on this code, what would be the best method to sort the subfolders by folder name before the IF statement is run on each file within the subfolders?

      

(in reply to ebgreen)
 
 
Post #: 10
 
 RE: Working With Subfolders - 6/7/2006 1:20:19 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: online
There isn't an easy way to sort the folder names. If you just want them sorted so that you can display the results in a sorted fashion, then I would consider using a disconnected recordset.

_____________________________

"... 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 who10)
 
 
Post #: 11
 
 RE: Working With Subfolders - 6/7/2006 8:29:13 AM   
  who10

 

Posts: 33
Score: 0
Joined: 4/29/2006
Status: offline
Well, the folder names I am actually working with have the date and time in the name.  I need them sorted by name before I copy files out of them.  Do you still think a disconnected recordset would be the best option?  If so, I'll start researching that route.

Thanks. 

(in reply to ebgreen)
 
 
Post #: 12
 
 RE: Working With Subfolders - 6/7/2006 10:14:21 PM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: online
I believe a little more problem definition is in order. I can't see any reason why you would need to sort the folders at all. It sounds more like you want to use the folder names as conditional criteria. Can you give some concrete examples of what exactly you are trying to do?

_____________________________

"... 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 who10)
 
 
Post #: 13
 
 RE: Working With Subfolders - 6/8/2006 10:42:34 AM   
  who10

 

Posts: 33
Score: 0
Joined: 4/29/2006
Status: offline
Sure.  Here's the situation.

We recieve data from another company.  The data comes in to one of our file shares as several subfolders with the date and timestamp embedded in the subfolder name, e.g.,

12345_ABCDEF_20060806150000_ABCDEF
12345_ABCDEF_20060806150100_GHIJKL
12345_ABCDEF_20060806160000_MNOPQ

One of my tasks is to search through these folders and copy files with a certian name and file extension to other directories on a different file share.  One of the requirements is to process these folders in the order of the date and timestamp in the name. 
This is being done because some of these subfolders have the same file in them and we want to make sure we get the latest file when we do our copy. 

My code is copying all the files to the correct directories, but I am unable to figure out how to tell it to sort by the date and timestamp in the subfolder name. 

(in reply to ebgreen)
 
 
Post #: 14
 
 RE: Working With Subfolders - 6/9/2006 1:03:12 AM   
  ebgreen


Posts: 5069
Score: 31
Joined: 7/12/2005
Status: online
If your only concern is to make sure that the most recent file is copied, then I would look at the .DateLastModified property of each file and only copy it if it is more recent than the file that is already in the folder. If it is more recent or if the file does not already exist, then copy it. Otherwise, move along.

_____________________________

"... 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 who10)
 
 
Post #: 15
 
 RE: Working With Subfolders - 6/9/2006 1:09:28 AM   
  who10

 

Posts: 33
Score: 0
Joined: 4/29/2006
Status: offline
Yes, that is my concern and that sounds like a great plan... Why didn't I think of that???

I'll give it a shot.

Thanks!

(in reply to ebgreen)
 
 
Post #: 16
 
 
 
  

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 >> Working With Subfolders 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