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
Problem with rename in CMD
Moderator: DosItHelp
Re: Problem with rename in CMD
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.
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
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
Re: Problem with rename in CMD
worked 100% tnx allot