I was needing to add a space between a file name and date. Right now with my dos batch script I get this:
test104-11-2012
I would like to add a space between test1 and 04 so it comes out like this:
test1 04-11-2012
Here is my script that I'm using:
ren c:\test\test.txt test1%date:~4,2%-%date:~7,2%-%date:~10%.txt
Please advise and thanks.
Need to add a space between filename and date
Moderator: DosItHelp
Re: Need to add a space between filename and date
Whenever you want a file to have spaces on its name, you have to enclose it in quotes.
Try this:
Personally, I see no reason to enclose the original filename (c:\test\test.txt) in quotes, but most people say that it's good to do so in order to get you used to quoting.
If you wish, change c:\test\test.txt to "c:\test\test.txt".
Try this:
Code: Select all
ren c:\test\test.txt "test1 %date:~4,2%-%date:~7,2%-%date:~10%.txt"
Personally, I see no reason to enclose the original filename (c:\test\test.txt) in quotes, but most people say that it's good to do so in order to get you used to quoting.
If you wish, change c:\test\test.txt to "c:\test\test.txt".
Re: Need to add a space between filename and date
I would suggest you rename files to:
or
(It is easier to sort files).
Saso
Code: Select all
YYYY-MM-DD test1.txt
or
Code: Select all
test1 YYYY-MM-DD
(It is easier to sort files).
Saso
Re: Need to add a space between filename and date
Hey everyone. That worked. Thanks and thanks for the tips. Much appreciated.