[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 299
  • Last Modified:

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?
0
Robert Pollick
Asked:
Robert Pollick
  • 2
1 Solution
 
Psy053Commented:
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

0
 
Psy053Commented:
Sorry, it can all be done via a single VBScript if you prefer, I just have a fascination doing it the other way.

Also, please note in the previous comment, the following line in Date.VBS:
strDate = Date - 21
should be:
strDate = Date - 5

I was just making sure that it would work as expected, but forgot to change it back before I posted.

Zip.VBS
strDate = Date - 5
StrDate = Replace(StrDate,"/","")

Set WshShell = WScript.CreateObject("WScript.Shell") 
WshShell.Run "C:\Tools\pkzipc.exe -add Original_" & StrDate & ".zip C:\PKZip\TEST\*.*"

Open in new window

0
 
Steve KnightIT ConsultancyCommented:
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
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now