1.

Solve : Create Directory with Date?

Answer»

Hi all.
I have to do a script that copy all files from a directory to another.
Before doing this, I WANT to create a backup of the target directory (if exist yet) in a new Directory named: xxx_%Date%
Where %Date% is obviously the Date when I run the script.
For doing this I have to change the current date format from gg/mm/aaaa to aaaa-mm-gg because otherwise the script create 3 directory (gg, gg\mm and gg\mm\aaaa)

HELP me please!You can use the following CODE snippet to split out the date into variables MM, DD, YY. You can use the variables however you need to contruct your batch file.

Note: if you are using a windows machine, check out using WinScript.

@echo off
For /f "tokens=1-7 delims=:/-, " %%i in ('echo exit^|cmd /q /k"prompt $D $T"') do (
For /f "tokens=2-4 delims=/-,() skip=1" %%a in ('echo.^|date') do (
set dow=%%i
set %%a=%%J
set %%b=%%k
set %%c=%%l
set hh=%%m
set min=%%n
set ss=%%o
)
)
echo %mm% %dd% %yy%

Good luck. I write this code on command prompt:
for /f "tokens=1-3 delims=/\ " %i in ("%DATE%") do echo %k-%j-%i

It works prompting :
2005-03-25

but if I put in in a batch file it doesn't work
Why?

Thanks
You need to use double percent signs inside a batch file:

for /f "tokens=1-3 delims=/\ " %%i in ("%DATE%") do echo %%k-%%j-%%i

Note: on my machine the result was 22-03-Tue

Hope this helps thanks
My script didn't work because I use %% for DATE too.
(%%DATE%)

I'm wondered of the result that the script dispays on your pc...

What is your S.O.?
I'm using XP Home. %DATE% get interpreted as DOW MM-DD-YY.

With each new version of DOS, then Windows, MS added extensions to the batch commands. Keep this in mind when writing batch files for use on older operating systems.

Good luck.Thanks A lot!!
I was looking for this script for a long time!!
It was very helpfull 4 me!

It worked using this sentence in WINXP:

for /f "tokens=1-3 delims=/\ " %%i in ("%DATE%") do md %%k-%%j-%%i


Thanks You!



Discussion

No Comment Found