rename file tgrough bat file

N

Natalia

dear all, i have file 1.txt which i'd like to rename to 1_<today_date>. txt
in bat file. For example today is 04.12.2008, i'd like to rename 1.txt to
1_20081204.txt, is it possible? Or in another words how to put sysdate value
to variable.
Thank you.
Natalia.
 
P

Pegasus \(MVP\)

Natalia said:
dear all, i have file 1.txt which i'd like to rename to 1_<today_date>.
txt
in bat file. For example today is 04.12.2008, i'd like to rename 1.txt to
1_20081204.txt, is it possible? Or in another words how to put sysdate
value
to variable.
Thank you.
Natalia.

It depends on your date format. Click Start / Run / cmd {OK}, then type this
command:
echo %date%{Enter}
What do you see?
 
N

Natalia

Pegasus (MVP) said:
It depends on your date format. Click Start / Run / cmd {OK}, then type this
command:
echo %date%{Enter}
What do you see?

hello, thank you very much for your answer.
i see: 05.12.2008
 
P

Pegasus \(MVP\)

Natalia said:
hello, thank you very much for your answer.
i see: 05.12.2008

OK. Try this:
@echo off
ren 1.txt "1_%date:.=%.txt"

or perhaps this:
@echo off
for /F "delims=. tokens=1-3" %%a in ('echo %date%') do ren 1.txt
"1_%%c%%b%%a.txt"

Note that line2 is a long line. Do not break it up!
 
N

Natalia

Pegasus (MVP) said:
OK. Try this:
@echo off
ren 1.txt "1_%date:.=%.txt"

or perhaps this:
@echo off
for /F "delims=. tokens=1-3" %%a in ('echo %date%') do ren 1.txt
"1_%%c%%b%%a.txt"

Note that line2 is a long line. Do not break it up!

Both variants are working! Thank you very much!
 

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