Login | |
|
 |
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
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
|
|