mid function in for loop

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
BD_CDN
Posts: 2
Joined: 22 Jun 2009 07:40
Location: Ontario

mid function in for loop

#1 Post by BD_CDN » 22 Jun 2009 07:56

Hi

I'm trying to extract characters from a string using the mid function inside a for loop. The string is from a text file. The characters I extract are used to build a command in a new batch file. I can't get the mid function to work in a for loop.

Any help???

Here's an example input file:
042N05
042O09
042O10

Here's what I want the command to look like in the new batch file:
call cv.bat 042 n 05
call cv.bat 042 o 09
call cv.bat 042 o 10

Here's the code:

set /p LFname=Enter the list file name:
set /p BFname=Enter the new batch file name:

setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in (%LFname%) do (
echo call cv.bat %%a:~0,3 %%a:~3,1 %%a:~4,2 >> %BFname%
)


Thanks

avery_larry
Expert
Posts: 391
Joined: 19 Mar 2009 08:47
Location: Iowa

#2 Post by avery_larry » 22 Jun 2009 11:44

UNTESTED:

Code: Select all

set /p LFname=Enter the list file name: 
set /p BFname=Enter the new batch file name:

setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in (%LFname%) do (
   set tmp_var=%%a
   echo call cv.bat !tmp_var:~0,3! !tmp_var:~3,1! !tmp_var:~4,2!>>%BFname%
)

BD_CDN
Posts: 2
Joined: 22 Jun 2009 07:40
Location: Ontario

solved

#3 Post by BD_CDN » 22 Jun 2009 13:03

That works great.

Thanks!

Post Reply