Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Get files starting with "whatever" string

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

 

 
  
  Printable Version
All Forums >> [General Forum] >> Other Programming/Scripting Languages >> Get files starting with "whatever" string
  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 >>
 Get files starting with "whatever" string - 5/4/2005 11:54:02 PM   
  mzohreh

 

Posts: 12
Score: 0
Joined: 2/3/2005
From: United Kingdom
Status: offline
Hi,

I have the following quesry which retrieves files from a directory and zips them to another location, if the files are older than 7 days. I would like to add another if statement to say move the file only if it starts with a certain string, but i'm not sure how to do this as my VB script skill are not great. Here's the script:

Option Explicit
dim destFile, sDate, sLastWeekDate, oFSO, sDirectoryPath, oFolder, oFileCollection, oFile, iDaysOld,oShell,iRC

'get date for week before to add to filename
sLastWeekDate = Date
sDate =day(sLastWeekDate) & "_" & month(sLastWeekDate) & "_" & year(sLastWeekDate)

destFile = "\\server\DevArchive$\"&sDate&".zip"

iDaysOld = 7
Set oFSO = CreateObject("Scripting.FileSystemObject")
sDirectoryPath = "E:\MSSQL_Dev_Backups\Website"
set oFolder = oFSO.GetFolder(sDirectoryPath)
set oFileCollection = oFolder.Files
Set oShell = CreateObject("WScript.Shell")


'Walk through each file in this folder collection.
'If it is older than 1 weeks (7) days, then move it.
For each oFile in oFileCollection
If oFile.DateLastModified < (Date() - iDaysOld) Then
iRC = oShell.Run("winzip32 -m " & destFile & " " & oFile, 1, True)
End If
Next

'Clean up
set oShell = nothing
Set oFSO = Nothing
Set oFolder = Nothing
Set oFileCollection = Nothing
Set oFile = Nothing

Any help would be appreciated.

Regards

M

_____________________________

M Zohreh
 
 
Post #: 1
 
 RE: Get files starting with "whatever" string - 7/25/2005 10:44:18 AM   
  Country73


Posts: 710
Score: 8
Joined: 8/25/2004
From: USA
Status: offline
I know your question has been out here for a while, so if you are still needing a solution...
One simple way would be to get your target folder and go through each file.
Split the path so that you are only dealing with the file name itself, then either use the Left/Right function to do your search on. If it matches, run your next step.
This example will locate "mylogfile.log"

'---------------------------------------------
Set FOLD = oFS.GetFolder(TARGET)
Set FIL = FOLD.Files                             
For each FIL1 in FIL
myFile = Split(FIL1,FOLD & "\")          'This will give you just the name of the file
     If Left(myFile(1),5)="mylog" Then
           'your function here
     End If
Next 

(in reply to mzohreh)
 
 
Post #: 2
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [General Forum] >> Other Programming/Scripting Languages >> Get files starting with "whatever" string 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