How do I rename multiple files after sorting by creation date? -
i want number files based on creation date rather based on old file names.
example: assume following files listed in descending order of creation date.
a.jpg d.jpg b.jpg c.jpg
i want rename these files such that
a.jpg becomes 4.jpg d.jpg becomes 3.jpg b.jpg becomes 2.jpg c.jpg becomes 1.jpg
i using windows 8 , have sorted files in folder based on creation date. however, when try rename files, dos ignores sorting , proceeds rename files based on old file names.
thus,
a.jpg becomes 1.jpg d.jpg becomes 4.jpg b.jpg becomes 2.jpg c.jpg becomes 3.jpg
i using following code (.bat file) got different post in website.
@echo off setlocal enabledelayedexpansion set oldext=jpg set newext=jpg set index=0 %%f in (*.%oldext%) ( set /a index+=1 set index=!index! ren "%%f" "!index!.%newext%" )
i not have scripting tools installed , creating basic .bat files using notepad.
thanks help.
in fat file systems files not ordered, placed included in folders. in ntfs files alphabetically ordered. can change how want see files, not how phisically ordered.
for
loops iterate on files in same order stored. if need iterate in different order, need create list in order want , iterate on list.
@echo off setlocal enableextensions disabledelayedexpansion set "oldext=jpg" set "newext=jpg" set "index=0" /f "delims=" %%a in ('dir /a-d /b /od "*.%oldext%"') ( set /a "index+=1" setlocal enabledelayedexpansion %%b in (!index!) endlocal & ren "%%~fa" "%%b.%newext%" )
here dir
command used list files in desired order , list iterated for /f
command.
the inner setlocal enabledelayedexpansion / endlocal
included handle case of files !
characters in names. if know never case, can directly use
@echo off setlocal enableextensions enabledelayedexpansion set "oldext=jpg" set "newext=jpg" set "index=0" /f "delims=" %%a in ('dir /a-d /b /od "*.%oldext%"') ( set /a "index+=1" ren "%%~fa" "!index!.%newext%" )
note none of included samples handle in way possibility of duplicate file names.
Comments
Post a Comment