M BUZZ CRAZE NEWS
// news

Batch rename multiple files by creation date [closed]

By David Jones

this is my first question in superuser. As you probably read in the title I would like to rename multiple files using a .bat file. I'm currently working on a project that involves books. In this case is important keep book chapters separate and named correctly, I have, for example 3 files in the same directory that are 3 chapters:

example.pdf created at 16:44 PM
anotherexample.pdf created at 16:45 PM
thelastexample.pdf created at 16:46 PM

I would like to rename them with a sequence of increasing numbers from 0 (0, 1, 2) in this case, but assigning numbers according to the date of creation.

So they can become:

1.pdf created at 16:44 PM
2.pdf created at 16:45 PM
3.pdf created at 16:46 PM

How can I do this using a batch file or a cmd command?

2

2 Answers

You can use this batch script:

@echo off
:: Put the path to the folder where the files should be renamed here:
set Folder=%userprofile%\desktop\Folder
For /f "Delims=" %%a in ('dir /od /tc /a-d /b "%Folder%"') do call :Rename "%%a" "%%~nxa"
exit
:Rename
set /a Counter+=1
ren "%Folder%\%~1" "%Counter% %~2"
goto :EOF

enter image description here

You can achieve this using powershell:

$i=0;dir|sort CreationTime|%{$i++;ren "$($_.fullname)" -newn {$i+$_.extension}}