adding prefix last modified date

January 3, 2011 at 07:51:45
Specs: Windows XP
Hello,

I want to run a batch that will rename the files in the directory starting with the last modified date:
for instance, if the file name was test_again.txt and was last modified at 13/02/2009 the new name should be
2009-02-13 test_again.txt
The batch will run over all the files in the directory.

Thanks
Yoko


See More: adding prefix last modified date

Report •


#1
January 3, 2011 at 13:11:08
Post the output of this bat:

======================================
@echo off > #& setLocal EnableDELAYedeXpansion

for /f "tokens=* delims= " %%a in ('dir/b #') do (
echo.%%~Ta %%a
)


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
January 3, 2011 at 13:16:46
@echo off
setLocal EnableDELAYedeXpansion

for /f "tokens=*" %%a in ('dir C:\ /b') do (
  :: Extract the files date.
  set T=%%~Ta
  set FileDay=!T:~3,2!
  set FileMonth=!T:~0,2!
  set FileYear=!T:~6,4!
  ren %%a !FileYear!-!FileMonth!-!FileDay!%%a
)

NOTE make sure you change the C:\ to the path you want to use. Probably do not want to rename your files in the the root folder.


Report •

#3
January 3, 2011 at 23:59:35
Thanks for the reply.
I can't use this script if the folder name has spaces. for example - it won't work on the "dir c:\documents and settings" folder.

I tried using the usebackq option, but couldn't figure the correct syntax..

please help

thnaks
Yoko


Report •

Related Solutions

#4
January 4, 2011 at 00:07:44
"I can't use this script "

WHAT script?


=====================================
Life is too important to be taken seriously.

M2


Report •

#5
January 4, 2011 at 00:09:51
I tried using the batch that was posted by ace_omega, I called that the script.

Report •

#6
January 4, 2011 at 07:11:21
Sorry. You have to soround it with quotes for folders that have spaces in the names...

@echo off
setLocal EnableDELAYedeXpansion

for /f "tokens=*" %%a in ('dir C:\ /b') do (
  :: Extract the files date.
  set T=%%~Ta
  set FileDay=!T:~3,2!
  set FileMonth=!T:~0,2!
  set FileYear=!T:~6,4!
  ren "%%a" "!FileYear!-!FileMonth!-!FileDay!%%a"
)

Hope that helps.


Report •

#7
January 4, 2011 at 20:53:23
Just think, if you had provided the info requested, you might be on your way to a solution.


=====================================
Life is too important to be taken seriously.

M2


Report •


Ask Question