Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Checking for patterns in files & Moving them into folders

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

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Checking for patterns in files & Moving them into folders
  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 >>
 Checking for patterns in files & Moving them into folders - 1/15/2008 3:21:34 PM   
  vinayak

 

Posts: 1
Score: 0
Joined: 1/15/2008
Status: offline
Hi All,

I have a folder structure as follows:

H:\Test\Archive\Archive2008-01-01

Now i need to run a vbscript to move all files in H:\Test which have the pattern 2008-01-01 and is a log file.
This is what i came up with:


      

Now, this works fine. But if there are no files that match the pattern in H:\Test, then the vbscript is not executed beyond this line.

Can somebody suggest any workaround or any other method to do this?
Thank you,
 
 
Post #: 1
 
 RE: Checking for patterns in files & Moving them into f... - 1/15/2008 5:07:34 PM   
  dm_4ever


Posts: 2641
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Since you know there maybe some folders that don't match your criteria....

sFileName = "H:\Test\" & "*" & "2008-01-01" & "*" & ".log"
sDirectoryName = "H:\Test\Archive\Archiveyyyy-mm-dd"
On Error Resume Next
objFile.MoveFile sFileName, sDirectoryName
On Error Goto 0

You could also loop through all the files checking to see if there is at least one file that matches your pattern, but that may be more work than its worth.

_____________________________

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 vinayak)
 
 
Post #: 2
 
 RE: Checking for patterns in files & Moving them into f... - 1/15/2008 8:26:25 PM   
  ehvbs

 

Posts: 2173
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
While I agree with dm_4ever, that 'looking before you jump' may not be worth
the additional effort (in general, you can't even skip the fallback of the errorhandling,
because the one matching folder could be removed after your check), I firmly
believe, that

  On Error Resume Next
  objFile.MoveFile sFileName, sDirectoryName
  On Error Goto 0

should look like

  On Error Resume Next
  objFile.MoveFile sFileName, sDirectoryName
  If <TooLazyToLookUpTheNumber> = Err.Number Then
      Err.Clear ' having nothing to backup isn't such a bad thing
  Else
      ' Tell the user that his backup failed!
      ' Set flags to indicate that the rest of the script has to act in a special way
  End If   
  On Error Goto 0

(in reply to dm_4ever)
 
 
Post #: 3
 
 
 
  

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 >> Checking for patterns in files & Moving them into folders 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