rename file tgrough bat file

  • Thread starter Thread starter Natalia
  • Start date Start date
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.
 
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?
 
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
 
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!
 
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!
 
Back
Top