Link to home
Start Free TrialLog in
Avatar of Bob
BobFlag for United States of America

asked on

Naming a Zip file the same as it's time stamp

I am zipping files that are "X" number of days old, but I need to name that zip file the same as the date the time stamp is. Such as I want to name zip files that are five days older than today. I am using PKZIPC to zip these files and my command line is; pkzipc -add Original_%date:~4,2%%date:~7,2%%date:~10,4%%-5% C:\PKZip\TEST\*.*  In the command the zip file name is set to name the file to the current date. Is there a switch that can be used to name the file to a name that would be 5 or 4 days before the current date. Such as today is 12192009 and I want the zip file to be named 12142009. Is there a switch that I can use with the %date:~4,2%%date:~7,2%%date:~10,4%%-5% format that will name the zip file as that older date?
Avatar of Psy053
Psy053
Flag of Australia image

Here's something I just knocked up quickly.

Basically, you run Zip.BAT, which calls Date.VBS which works out the current date, and subtracts 5 days. Then Zip.BAT uses the date returned to name the ZIP file.








(Zip.BAT)
@echo off
For /F "delims=" %%A  in ('cscript //nologo c:\data\scripts\misc\date.vbs') do Set DateNeg5=%%A
pkzipc -add Original_%DateNeg5%.zip C:\PKZip\TEST\*.*

(Date.VBS)
strDate = Date - 21
StrDate = Replace(StrDate,"/","")
WScript.Echo StrDate

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Psy053
Psy053
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Steve Knight
Not to take anything away from the solutions above (which are fine), I often have to do this sort of thing in batch and to make sure the VBS is available you can also create it on the fly, i.e. to create the VBS shown above (brought into one line to make it easier) you just need one line to echo the line needed into a temporary VBS file:

@echo off
echo wscript.echo replace((date - 5),"/","")> "%temp%\date-5.vbs"
For /F "delims=" %%A  in ('cscript //nologo "%temp%\date-5.vbs"') do Set DateNeg5=%%A
pkzipc -add Original_%DateNeg5%.zip C:\PKZip\TEST\*.*
del "%temp%\date-5.vbs" 2>NUL

Steve