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?

kedpayne2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pbarretteCommented:
Hi kedpayne2,

To get the current date in NT, this is the correct command:
---------
FOR /F "TOKENS=2-5 DELIMS=/ " %%F IN ('DATE /T') DO (
 SET MM=%%F
 SET DD=%%G
 SET YYYY=%%H
)
---------

This command parses the output of the "DATE /T" command and places the results into variables which reflect the current date.

To copy your TEXT.TXT file, you would have a batchfile which contained the following:
:: ------EXAMPLE.BAT---------
@ECHO OFF
FOR /F "TOKENS=2-5 DELIMS=/ " %%F IN ('DATE /T') DO (
 SET MM=%%F
 SET DD=%%G
 SET YYYY=%%H
)
SET CURDATE=%MM%%DD%%YYYY%
COPY C:\TEXT.TXT C:\%CURDATE%.TXT
:: ------EXAMPLE.BAT---------

If you just wanted to rename the file, you could use "REN" instead of the "COPY" command.

pb
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
billiousCommented:
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


0
pbarretteCommented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows OS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.