Page 1 of 1

rename file but keep the date

Posted: 04 Mar 2013 15:35
by daillest319
Im having a bit of trouble renaming two files. any help would be great. what im trying to do is

rename

bl6620.x1.BLU.130303.TXT
bl6620.x1.BLU.130302.TXT

the date is at the end yymmdd. this always changes. here what i need the files to look like

bl6620_x1_BLU_130303.TXT
bl6620_x1_BLU_130302.TXT


here the code im trying to make work at the moment


Code: Select all


REN "C:\TEST\bl6620.x1.BLU.130302.TXT" bl6620_x1_BLU_*.TXT



Re: rename file but keep the date

Posted: 04 Mar 2013 15:53
by foxidrive
try this: (untested)

Code: Select all

@echo off
for %%a in (bl6620.x1.BLU.*.TXT) do call :next "%%~a"
pause
goto :EOF
:next
set "name=%~n1"
set "name=%name:.=_%"
ren "%~1" "%name%%~x1"

Re: rename file but keep the date

Posted: 04 Mar 2013 18:13
by daillest319
works lovely thank you so much :D .


is it possbile you can explain what each line is doing?

Re: rename file but keep the date

Posted: 04 Mar 2013 23:51
by foxidrive
daillest319 wrote:is it possbile you can explain what each line is doing?


In essence it uses a loop to send each filename to the :next subroutine
and the subroutine gets the filename into a varable, changes the . to _
and then renames the original filename to the changed filename.

Tell me which bits you need more info on.