Link to home
Start Free TrialLog in
Avatar of kedpayne2
kedpayne2

asked on

Date stamping batch file "copy" file

I read several articles on date stamping the output of a batch file "copy" cmd....but was unsure how to apply the fix given. The following:
++++++++++++++++++++++++++++++++++++++++++++
The syntax you gave would work fine on 2000 but not NT4 as the date/time are not environment variables within NT4.
One caveat to this is you need a space after the / delimiter or it won't skip the day, thus:
for /f "tokens=2-4 delims=/ " %%i in ("%DATE%") do set d=%%k%%i%%j
your line for the time looks fine unaltered.
With NT4, as billious has commented you need to use TIME /T and DATE /T to output the date/time, surrounded by single quotes instead of doubles.
+++++++++++++++++++++++++++++++++++++++++++++
This is to advanced for me. How would apply this if I wanted to use copy c:\text.txt c:\(date).txt?

Could someone help me?

ASKER CERTIFIED SOLUTION
Avatar of pbarrette
pbarrette

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 billious
billious

One little nit-pick:

FOR /F "TOKENS=2-4 DELIMS=/ " %%F IN ('DATE /T') DO (
SET MM=%%F
SET DD=%%G
SET YYYY=%%H
)

Note "2-4", not "2-5" ('though 2-5 would work)

Oh - and this assumes mm/dd/yyyy format. For dd/mm/yy format
FOR /F "TOKENS=2-4 DELIMS=/ " %%F IN ('DATE /T') DO (
SET MM=%%G
SET DD=%%F
SET YYYY=%%H
)

Equivalently, since 'time/t' output is hh:mm then the command
FOR /F "TOKENS=1-2 DELIMS=: " %%F IN ('TIME /T') DO (
SET MN=%%F
SET HH=%%G
)

sets HH as current-hour and MN as current-minutes

Aside to pb:

Microsoft have conveniently changed the output of "date/t" to OMIT the dayname for XP. Just thought you'd like to know.

...Bill


Hi kedpayne2,

Glad to help.

Bill,

You're right about the "2-4" thing, I was copying out from memory and just added the 2nd token + 3 tokens total..

I use XP at home and hadn't noticed the missing dayname. I don't have my telnet server up today so I can't check myself, but I usually parse out %TIME% on 2K/XP so I haven't run into that issue yet.

pb