views:

34

answers:

3

Hi, I tried the script below to create a timestamp directory in one of my drives, for some reason is giving me a syntax error on the last string where it create the directory. See below.

:: Code begins....
pause
W:
pause
cd W:\VL2000_AMF\AMF_Archive
pause
for /F "tokens=1-4 delims=. " %%i in ('date /t') do (
set Day=%%i
set Month=%%j
set Year=%%k
)
pause
for /F "tokens=1-4 delims=: " %%i in ('time /t') do (
set Hour=%%i
set Minute=%%j
set Second=%%k
)
pause
md %1\%Year%-%Month%-%Day%
pause
:: Code ends....
A: 

Should your %%1 be %1?

Brian Nixon
I did that, but I still get the same syntax error.
Patron0119
A: 

I used the following on Windows 2000 and 2003 to get year, month, and day from the date command output. Unfortunately, I no longer have any XP systems to see if this will work there.

for /F "tokens=2-4 delims=/ " %%i in ('date /t') do (
echo "Day=%%i"
echo "Month=%%j"
echo "Year=%%k"
)

What is the format of "date /t" and "time /t" output on XP?

joast
Depends on locale, I expect.
Brian Nixon
Yes, the date output should depend upon locale. However, I don't know if that is true with XP or not since I no longer have any systems with it installed.
joast
A: 

Are you sure your date is coming back as mm.dd.yyyy (separated by dots, and with the fields in the order you expect)? If the process's locale is not what you expect, you might be ending up with %Day% as something like 8/17/2010, which would cause md to report a syntax error as it tries to interpret /17 and /2010 as options.

Brian Nixon