PDA

View Full Version : Rename a file in Dos to datestamp??


Derek
January 6th 04, 02:00 AM
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

David Candy
January 6th 04, 02:02 AM
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.=20

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=3DE tokens=3D4,5,6,7,8* delims=3D/, " %%i in (date.txt) do =
Set Z=3D%%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


--=20
----------------------------------------------------------
http://www.g2mil.com/Dec2003.htm
"Derek" > wrote in message =
...
> What is the syntax used in a batch file to rename a file=20
> to the file's creation time/date in WinXP? Alternatively,=20
> even renaming to the current system time/date would do?
>=20
> I have tried searching for this, but have drawn a blank.
>=20
> Your advice would be appreciated!
>=20
> Thanks
>=20
> Derek

January 6th 04, 02:07 AM
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.<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
>
>
>--
>----------------------------------------------------------
>http://www.g2mil.com/Dec2003.htm
>"Derek" > wrote in
message ...
>> 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
>
>.
>

David Candy
January 6th 04, 02:11 AM
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.
..

--=20
----------------------------------------------------------
http://www.g2mil.com/Dec2003.htm
> wrote in message =
...
> many thanks. only problem is this adds the date to the end=20
> of any filename, so the file extension is effectively=20
> lost. don't suppose you know how to add it to the start??
>=20
> thanks
>=20
>=20
> >-----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=20
> GMV3535.<original name>.jpg
> >
> >The case of the A (as in %A or %~<letter>A) is important.=20
> FOR/IN/DO is uppercase to highlight the actual command=20
> syntax.=20
> >
> >Windows help has all the info
> >
> >I went and did the hard work for you, but it can be=20
> optimised. As this is so boring I was leaving optimisation=20
> to you.
> >
> >@echo off
> >echo. |date>date.txt
> >FOR /F "eol=3DE tokens=3D4,5,6,7,8* delims=3D/, " %%i in=20
> (date.txt) do Set Z=3D%%k-%%l-%%m
> >move "%~1" "Z%%~1%"
> >del date.txt
> >
> >Make a batch file with these lines in it, drop a folder=20
> on it, folder renamed.
> >
> >New Folder becomes New Folder01-12-2003
> >
> >
> >--=20
> >----------------------------------------------------------
> >http://www.g2mil.com/Dec2003.htm
> >"Derek" > wrote in=20
> message ...
> >> What is the syntax used in a batch file to rename a=20
> file=20
> >> to the file's creation time/date in WinXP?=20
> Alternatively,=20
> >> even renaming to the current system time/date would do?
> >>=20
> >> I have tried searching for this, but have drawn a blank.
> >>=20
> >> Your advice would be appreciated!
> >>=20
> >> Thanks
> >>=20
> >> Derek
> >
> >.
> >

Google