Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
daillest319
- Posts: 27
- Joined: 31 Jan 2012 14:45
#1
Post
by daillest319 » 04 Mar 2013 15:35
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
Last edited by
daillest319 on 04 Mar 2013 19:48, edited 1 time in total.
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#2
Post
by foxidrive » 04 Mar 2013 15:53
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"
-
daillest319
- Posts: 27
- Joined: 31 Jan 2012 14:45
#3
Post
by daillest319 » 04 Mar 2013 18:13
works lovely thank you so much
.
is it possbile you can explain what each line is doing?
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#4
Post
by foxidrive » 04 Mar 2013 23:51
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.