Rename a file in Dos to datestamp??

  • Thread starter Thread starter Derek
  • Start date Start date
D

Derek

What is the syntax used in a batch file to rename a file
to the file's creation time/date in WinXP? Alternatively,
even renaming to the current system time/date would do?

I have tried searching for this, but have drawn a blank.

Your advice would be appreciated!

Thanks

Derek
 
These snippets should help

FOR %A IN (*.jpg) DO ren "%A" "GMV3535.%~nA%~xA"

Will change all jpg files in a folder to GMV3535.<original name>.jpg

The case of the A (as in %A or %~<letter>A) is important. FOR/IN/DO is uppercase to highlight the actual command syntax.

Windows help has all the info

I went and did the hard work for you, but it can be optimised. As this is so boring I was leaving optimisation to you.

@echo off
echo. |date>date.txt
FOR /F "eol=E tokens=4,5,6,7,8* delims=/, " %%i in (date.txt) do Set Z=%%k-%%l-%%m
move "%~1" "%~1%Z%"
del date.txt

Make a batch file with these lines in it, drop a folder on it, folder renamed.

New Folder becomes New Folder01-12-2003
 
many thanks. only problem is this adds the date to the end
of any filename, so the file extension is effectively
lost. don't suppose you know how to add it to the start??

thanks

-----Original Message-----
These snippets should help

FOR %A IN (*.jpg) DO ren "%A" "GMV3535.%~nA%~xA"

Will change all jpg files in a folder to
GMV3535. said:
The case of the A (as in %A or %~<letter>A) is important.
FOR/IN/DO is uppercase to highlight the actual command
syntax.
Windows help has all the info

I went and did the hard work for you, but it can be
optimised. As this is so boring I was leaving optimisation
to you.
@echo off
echo. |date>date.txt
FOR /F "eol=E tokens=4,5,6,7,8* delims=/, " %%i in
(date.txt) do Set Z=%%k-%%l-%%m
move "%~1" "%~1%Z%"
del date.txt

Make a batch file with these lines in it, drop a folder on it, folder renamed.

New Folder becomes New Folder01-12-2003
message news:[email protected]...
 
Yes I just don't know exactly how you are going to use this.

Should do it. %Z% contains the date in a legal filename format (no /)
move "%~1" "%Z%%~1"

Type for /? and look for all the %~<variable> to see how to pull parts out of a filename.
..
 
Back
Top