Need to add a space between filename and date

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
texastig
Posts: 2
Joined: 11 Apr 2012 08:33

Need to add a space between filename and date

#1 Post by texastig » 11 Apr 2012 08:42

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.

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: Need to add a space between filename and date

#2 Post by Fawers » 11 Apr 2012 10:03

Whenever you want a file to have spaces on its name, you have to enclose it in quotes.
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".

miskox
Posts: 555
Joined: 28 Jun 2010 03:46

Re: Need to add a space between filename and date

#3 Post by miskox » 11 Apr 2012 10:11

I would suggest you rename files to:

Code: Select all

YYYY-MM-DD test1.txt


or

Code: Select all

test1 YYYY-MM-DD


(It is easier to sort files).

Saso

texastig
Posts: 2
Joined: 11 Apr 2012 08:33

Re: Need to add a space between filename and date

#4 Post by texastig » 11 Apr 2012 12:17

Hey everyone. That worked. Thanks and thanks for the tips. Much appreciated.

Post Reply