Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Name: reno
i need help to rename the following filename with non-standard timestamp to yyyymmdd:
xxxx ddmmm.ext -> xxxx yyyymmdd.ext
xxxx dmmm.ext -> xxxx yyyymmdd.ext
xxxx mmmdd.ext -> xxxx yyyymmdd.ext
xxxx mmmd.ext -> xxxx yyyymmdd.ext
notes: file name with different naming convention than above should be ignored.sample file list (Old_Name -> NEW_NAME) :
"INDEX XX NOV.xls" -> ignore
"price 10-14nov.xls" -> ignore
"PRICE NOV.xls" -> ignore
"today 10nov.xls" -> today 20081110.xls
"today des3.xls" -> today 20081203.xls
"orders 7nov.pdf" -> orders 20081107.pdf
here is my incomplete code:
(still cant figure out reading current timestamp and convert it to yyyymmdd in :renamefile function)@echo off
setLocal EnableDelayedExpansioncall :renamemonth nov 11
::call :renamemonth des 12goto :exit
:renamemonth
echo Processing Month:%1
for /f "tokens=* delims=" %%f in ('dir /b *%1*.*') do (
call :renamefile %1 %2 "%%f"
):renamefile
set fileonly=%~n3
set extonly=%~x3
for /f "tokens=1* delims= " %%a in ("%fileonly%") do (::here is where i stuck
echo %%b|findstr " [0-9][0-9]%1" > null
if Not ErrorLevel 1 (
set timestamp=2008%2dd
echo ren %3 "%%a !timestamp!%extonly%"
) else (
echo ..not match=%3
)
)
:exit

reno,
If you can afford to use a free cmd.exe replacement called tcc/le by jpsoft, this is a cakewalk:
22:54:12 C:\...\t>for %a in (*.txt) do echo %@filedate[%a,w,4] --- %a
2008-12-12 --- doctype.txt
2008-12-09 --- moneyfile.txt
2008-12-09 --- runningtotal.txt
2008-12-03 --- workids.txt
2008-12-12 --- y.txt
23:00:18 C:\...\t>for %a in (*.txt) do echo %@replace[-,,%@filedate[%a,w,4]]-%@replace[:,,%@filetime
[%a]] --- %a
20081212-1220 --- doctype.txt
20081209-1151 --- moneyfile.txt
20081209-1151 --- runningtotal.txt
20081203-1808 --- workids.txt
20081212-1245 --- y.txt23:00:27 C:\...\t>
Otherwise, all the best :-).--
Holla.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |