On Mon, 04 Aug 2003 06:53:38 -0500, 
=?windows-1252?Q?Jos=E9=20Antonio=20Pineda=20Figueroa?= 
<[EMAIL PROTECTED]> wrote:

> c:\>for %f in (*.mes *.txt *.c my_fil*.*) do find "hello world" %f

I've used a similar construction many times. The problem is that the
return from the FIND command is always the file it is testing, plus the
lines containing the text string, if found. So the above gives a string
of results, good and bad ones,  usually too fast to note.

One cure is to add >>found.txt  at the end. This saves the results in a
text file that can be checked afterwards.

Or another way is to put the FIND command in a batch file where it is
followed by PAUSE to allow the operator to read the result before the
next file is checked.

The FOR command can also be included in the batch file and the file made
recursive as in the following, which is a form I've used several times.

   rem example batch file: find "hello world" in *.mes files
   if %1'==FIND' goto find
   for %%k in (*.mes) do call %0 FIND %%k
   goto exit
   :find
   find "hello world" %2
   pause
   :exit

Or it can be doubly recursed to check archived files like this:

   rem another example batch file to find "hello world"
   rem   in archived *.MES files
   if %1'==UNZIP goto unzip
   if %1'==FIND goto find
   for %%k in (*.ZIP) do call %0 UNZIP %%k
   goto exit
   :unzip
   PKUNZIP ..\%2 *.mes
   for %%f in (*.mes) do call %0 FIND %%f
   del *.mes
   :find
   find "hello world" %2
   pause
   :exit

I leave it to the reader to work out how to pass the file extension and
text strings to the batch file from the command line.

Of course you could write the above as separate batch files as
FIND1.BAT, FIND2.BAT, FIND3.BAT, but the recursive method keeps it neat,
and if it is moved or copied you know you have the whole of it in one.

Greg

-- Arachne V1.71;UE01, NON-COMMERCIAL copy, http://arachne.cz/

Reply via email to