asked on
@echo off
REM Define file and folder locations
set BaseDir=c:\TestFiles
set DestZip=c:\OldLogs\output.zip
set z=c:\program files\7-zip\7z.exe
REM Zip all files and folders
"%z%" a -tzip "%DestZip%" -r "%BaseDir%\*.*"
Dim fso, startFolder, OlderThanDate, objShell, strCommand, BaseDir, DestZip, zipexe
Set fso = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
BaseDir = "=c:\TestFiles\" ' folder for source data
DestZip = "c:\OldLogs\" & right(left(Date,8),2) & right(left(Date,5),2) & left(Date,2) & "-" & left(Time,2) & right(left(Time,5),2) & right(left(Time,8),2) & ".zip"
OlderThanDate = DateAdd("d", -3, Now)
zipexe = "c:\program files\7-zip\7z.exe"
"%z%" a -tzip "%DestZip%" -r "%BaseDir%\*.*"
strCommand = """" & zipexe & """ a -tzip " & DestZip " """ & BaseDir & "*.*"""
objShell.Run strCommand, 1, True
DeleteOldFiles BaseDir, OlderThanDate
Function DeleteOldFiles(folderName, BeforeDate)
Dim folder, file, fileCollection, folderCollection, subFolder
Set folder = fso.GetFolder(folderName)
Set fileCollection = folder.Files
For Each file In fileCollection
If file.DateLastModified < BeforeDate Then
fso.DeleteFile file
End If
Next
End Function
ASKER
1) Delete the old files from C:\TestFile where older than x daysNow you write:
2) The output.zip needs to increment each time the script is run, a time stamp would be ideal here
I only want to ZIP AND DELETE the logs which are OVER 30 days old. If they are NOT older than 30 days, can we ignore them?Just to make sure I understood you correctly: Basically, you want to move only files older than a certain age to an archive, while keeping the more recent files in the same location?
ASKER
Batch files are text files containing a script of commands that are executed by the command interpreter on DOS, OS/2 and Windows systems. Most commonly, they are used to perform a series of functions that are repeated -- copying a set of files created daily with one step, for example.
TRUSTED BY
Open in new window