Cut-n-paste the following into notepad and save it as a .BAT file:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: |
@echo off
setlocal enabledelayedexpansion
set filespec=%*
if "%filespec%"=="" goto :help
for /f "delims=" %%F in ('dir/a-d/b/od %filespec%') do (
set fn=%%~tF
set/a hour=0x!fn:~11,2!
if !hour! GTR 10 set/a hour=(!hour!-6^) %% 12
if "!fn:~17,2!"=="PM" set/a hour+=12
if !hour! LSS 10 set hour=0!hour!
set root=%%~dpF
set ext=%%~xF
set nxt=00
set fn=!fn:~6,4!!fn:~0,2!!fn:~3,2!_!hour!!fn:~14,2!
if exist "!root!!fn!!nxt!!ext!" for /L %%I in (59,-1,1) do (
set dup=0%%I
if not exist "!root!!fn!!dup:~-2!!ext!" set nxt=!dup:~-2!
)
@echo ren "%%F" "!fn!!nxt!!ext!"
ren "%%F" "!fn!!nxt!!ext!"
)
dir !root!*!ext! | find/v "Volume"
goto :end
:help
@echo.
@echo Renames files to the date and time the file was created,
@echo preserving the file extention: YYYYMMDD_HHMMSS.ext
@echo Synatx: %0 filespec [/s]
@echo A filespec (such as *.jpg) must be specified.
@echo /s will recurse sub-folders and rename files matching the filespec.
@echo Example: %0 E:\DCIM\*.jpg /s
:end
endlocal |