Computing.Net > Forums > Programming > batch script to convert timestamp

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

batch script to convert timestamp

Reply to Message Icon

Name: reno
Date: December 18, 2008 at 07:01:21 Pacific
OS: XP
CPU/Ram: P4 & 1GB
Product: Asus / NOTEBOOK
Comment:

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 EnableDelayedExpansion

call :renamemonth nov 11
::call :renamemonth des 12

goto :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



Sponsored Link
Ads by Google

Response Number 1
Name: Holla
Date: December 18, 2008 at 09:31:38 Pacific
Reply:

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.txt

23:00:27 C:\...\t>


Otherwise, all the best :-).

--
Holla.


0
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: batch script to convert timestamp

batch script to upload to ftp www.computing.net/answers/programming/batch-script-to-upload-to-ftp/16987.html

batch script to parse filenames www.computing.net/answers/programming/batch-script-to-parse-filenames/15286.html

XP batch script to rename files www.computing.net/answers/programming/xp-batch-script-to-rename-files/14608.html