I'm new to the forum and I need help trying to create a batch file to do the following:
I have a bunch of log files that I need to zip and I would like to automate the process.
The filenames are in the format LOGMMDDYYYY.csv - where the MMDDYYYY portion is a particular date that the log file was created. The problem is that the log for the current day will be locked because it is in use by the program; therefore, I would like to create a batch file that would take all the logs before the current date and zip them and then move them to another folder.
Is this possible to do with a batch file?
Thanks for any help you may be able to give.
Batch File Help Need: Zip all files before the current date.
Moderator: DosItHelp
-
- Expert
- Posts: 80
- Joined: 04 Feb 2009 10:03
Based on your system date (%Date%) being something like "02/23/2009", you could start with something like:
Modify the "Zip" line to your specifications and zip program.
It's crude, but it's a start...
-Rick
Code: Select all
Set "WD=%Date%"
Set "dMM=%WD:~0,2%"
Set "dDD=%WD:~3,2%"
Set "dYY=%WD:~6,4%"
Set "dYY2=%WD:~8,2%"
Set "dMMDDYYYY=%dMM%%dDD%%dYY%"
Set "TodaysLog=LOG%dMMDDYYYY%.csv"
For /F "Delims=" %%F in ('Dir Log*.csv') do (
If /I [%%F] NEQ [%TodaysLog%] Zip -a %%F ZipFile
)
Modify the "Zip" line to your specifications and zip program.
It's crude, but it's a start...
-Rick
You could use:
Instead of:
Code: Select all
FOR /F "DELIMS=" %%$ IN ('DIR LOG*.CSV') DO (
IF /I [%%$] NEQ [LOG%DATE:/=%.CSV] ZIP -a %%$ ZIPFILE
)
Instead of:
Code: Select all
Set "WD=%Date%"
Set "dMM=%WD:~0,2%"
Set "dDD=%WD:~3,2%"
Set "dYY=%WD:~6,4%"
Set "dYY2=%WD:~8,2%"
Set "dMMDDYYYY=%dMM%%dDD%%dYY%"
Set "TodaysLog=LOG%dMMDDYYYY%.csv"
For /F "Delims=" %%F in ('Dir Log*.csv') do (
If /I [%%F] NEQ [%TodaysLog%] Zip -a %%F ZipFile
)