Using output of DATE for zip file name

K

Kok Yong Lee

Hi there,

I was trying to setup a routine backup of my data with the day of backup as
the name of file.

for example

wzzip 24_03_2006.zip Z:\data\*.*

Currently DATE /t on my machine return "24/03/2006"

I been messing about with the ideas of using the | in order to retrieve the
resutls from "DATE /t" and then feed it to wzzip as input by to avail. Any
one care to shed some light on this ?

thanks in advanced.
 
T

Timo Salmi

Kok said:
wzzip 24_03_2006.zip Z:\data\*.*
Currently DATE /t on my machine return "24/03/2006" I been
messing about with the ideas of using the | in order to retrieve
the resutls from "DATE /t" and then feed it to wzzip as input by
to avail. Any one care to shed some light on this ?

What you need is a method for getting the date elements into
environment variables and the utilizing those in a zip call. The
tricks are explained e.g. in

1} How to get today's date elements into environment variables?
157253 Mar 9 2006 ftp://garbo.uwasa.fi/pc/link/tscmd.zip
tscmd.zip Useful NT/2000/XP script tricks and tips, T.Salmi

Be aware that the date results (the order) can be locale dependent.

All the best, Timo
 
T

Timo Salmi

Timo said:
Be aware that the date results (the order) can be locale dependent.

I'll give the custom code. Assume that DATE /T gives 24.03.2006
As I said, the outcome can differ between locales. But if the format
is that (or 23/03/2006) then

@echo off & setlocal enableextensions
:: Get the date elements
for /f "tokens=1-3 delims=./-" %%f in ('date /t') do (
set today_=%%h%%g%%f
set dd_=%%f
set mm_=%%g
set yyyy_=%%h)
::
:: Remove the potential trailing space from the year
set yyyy_=%yyyy_:~0,4%
::
:: An extra precaution which may be unncessarry
:: See to it that days 1-9 will always have a leading zero
set dd_=0%dd_%
set dd_=%dd_:~-2%
::
:: When you are sure, remove the echo precaution
echo wzzip %dd_%_%mm_%_%yyyy_%.zip Z:\data\*.*
endlocal & goto :EOF

Testing this script one will get
C:\_D\BAS>cmdfaq
wzzip 24_03_2006.zip Z:\data\*.*

All the best, Timo
 
K

Kok Yong Lee

Hi Timo,

thanks for the speedy response.

i tried the following nad it seems working fine for me. Just wonder in your
suggestions "delims=./-", is the hyphen part of the delimiter char as well
or it has some other meanings?


call :TODAY_DATE
call wzzip -r -P c:\lee\backup\%TheDate%.zip z:\scripts z:\tools z:\ita
z:\automations
goto :END

:TODAY_DATE
for /f "tokens=1-3 delims=./ " %%f in ('date /t') do (
set dd_=%%f
set mm_=%%g
set yyyy_=%%h)
REM echo %today_%
REM echo dd_=%dd_% mm_=%mm_% yyyy_=%yyyy_%
set TheDate=%yyyy_%_%mm_%_%dd_%
echo %TheDate%
goto :END

:END
endlocal
 
T

Timo Salmi

Kok said:
i tried the following nad it seems working fine for me. Just
wonder in your suggestions "delims=./-", is the hyphen part of the
delimiter char as well or it has some other meanings?

It is "part of the delimiter char". The demlims I used are meant to
cover three date format separator alternatives:
24.03.2006
24/03/2006
24-03-2006

All the best, Timo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top