|Hi. I am trying to write a batch script that will rename files in a directory to the contain the directory name, a number, and the date and time. I will post below a script I found that sort of does what I want. I would like to be able to define which directory contains the files I want to rename. When the script is in the directory with the files, it renames the files and does the numbering just the way I want, but I cannot figure out for the life of me how to get it to add the date/time to the file name. So the two things I want to be able to do is to define the location of the directory, instead of it being any directory below the script and also append a date and time stamp as part of the renamed file(s).|
Thanks for your help!
for /d /r %%a in (*.*) do (
call :LastDir %%a
call :NoFiles %%a
call :ReName %%a
:Zeros %1 %2
if %2 GEQ 10 (set /a y-=1) & if %2 GEQ 100 (set /a y-=1)
if %2 GEQ 1000 (set /a y-=1) & if %2 GEQ 10000 (set /a y-=1)
for /l %%c in (1,1,50) do (
if !C!==\ (set E=!D! & set D=)
for /f %%a in ('dir /b "%*" ^| findstr /b "!Dirs!_[0-9][0-9][0-9]"') do set /a
for %%a in ("%*\*.*") do set Found=Yes
if not "!Found!" EQU "Yes" exit /b
for /f "tokens=*" %%a in ('dir /b /a-d "%*" ^| findstr /v "!Dirs!_[0-9][0-9][0-9]"') do (
set /a Count+=1
call :Zeros 2 !Count!
ren "%*\%%a" "!Dirs!_!Num!%%~xa"