Problem with rename in CMD

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
slade2000
Posts: 2
Joined: 12 Dec 2011 02:41

Problem with rename in CMD

#1 Post by slade2000 » 12 Dec 2011 02:47

Hi

I have the following problem with a rename command on a machine. I want to rename a file so that it contains the date.

ren test.txt test%date%.txt

on my Win7 mashine it works fine, on XP pc next to me work fine but but if i remote desktop into another xp machine it does not work. A normal rename "ren test.txt test123.txt" does work. What can this be?

Tnx

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Problem with rename in CMD

#2 Post by dbenham » 12 Dec 2011 07:24

Window's treats forward slash (/) the same as backslash (\); it is a folder delimiter. Folder delimiters cannot appear in a file name. I always replace / with - when I want to include a date in a name.

If all you need is to get the local date format into the name, then you can use the following.

Code: Select all

set "dt=%date%"
ren "test.txt" "test%dt:/=-%.txt"

If you want to use the date in a consistent format, then there is more work to be done, and it is not trivial. I like to use year-month-day format so that the file names will sort chronologically. But parsing the date properly is difficult if you don't know ahead of time what the local date format is. The "universal" %DATE% parser shows one method that can help. (I suggest reading the entire thread).

Dave Benham

slade2000
Posts: 2
Joined: 12 Dec 2011 02:41

Re: Problem with rename in CMD

#3 Post by slade2000 » 13 Dec 2011 23:21

worked 100% tnx allot

Post Reply