- Using FIND in for loop - Text file input
- Posted by Ernesto on July 28th, 2005
Batch file for Windows XP - Currently using this code to get one string
in a text file:
FOR /F "eol=; tokens=*" %%i in (%buildStartTextFile%) do set
binaryDestination=%%i
This works great for grabbing one string, but I want to grab different
strings at different times. This is what is written in the text file:
firmware=C:\firmware
binary=C:\binary
I want to have two different 'for' loops with the 'find' function. I
want to search for the keywords "firmware" and "binary" then put those
directory strings into variables (binaryDestination,
firmwareDestination). Unsure how to use find in a for loop gracefully.
Already looked at for /? and find /?
THANKS!!!
- Posted by Phil Robyn on July 28th, 2005
Ernesto wrote:
To answer your question about 'for' loops, see the following:
- - - - - - - - - - begin screen capture WinXP - - - - - - - - - -
C:\cmd>type c:\temp\TheTextFile.txt
firmware=C:\firmware
binary=C:\binary
C:\cmd>demo\FirmBin
firmware=C:\firmware
binary=C:\binary
C:\cmd>wyllist demo\FirmBin.cmd
==========begin file C:\cmd\demo\FirmBin.cmd ==========
01. @echo off
02. setlocal
03. for %%a in (firmware binary) do (
04. for /f "tokens=2 delims==" %%b in (
05. 'find "%%a" c:\temp\TheTextFile.txt'
06. ) do set %%a=%%b
07. set %%a
08. )
==========end file C:\cmd\demo\FirmBin.cmd ==========
- - - - - - - - - - end screen capture WinXP - - - - - - - - - -
However, there is a simpler (one-line) way to achieve the same result:
for /f "tokens=*" %%a in (c:\temp\TheTextFile.txt) do set %%a
If you try the preceding at the CMD prompt rather than in a batch file,
use '%a' instead of '%%a'.
Since you are using Windows XP, you should refrain from using the
alt.msdos.batch newsgroup and instead switch to alt.msdos.batch.nt.
--
Phil Robyn
Univ. of California, Berkeley
- How to find which thread is in infinite loop? (Development Resources) by glchin@hotmail.com
- Getting input from a text file (MS-DOS) by Ernesto
- find and replace a string in a text file...possible with a batch file? (MS-DOS) by KILOWATT
- Windows 2003 - Find / Replace text in file utility? (Windows Server) by Shikari Shambu
- file find text search (Software & Applications) by Seattle Norm

