Batch script to search for a string and return the result
Zorc
-
dubcek Posted messages 18627 Registration date Status Contributor Last intervention -
dubcek Posted messages 18627 Registration date Status Contributor Last intervention -
Hello,
I am facing a problem with my batch script.
Here is the process of the script that I would like to set up:
For all the files in c:\dossier\*.txt, search for the string "toto". If the file contains this string "toto", return the path of this file in c:\resultat.txt
Here is what I have tried but does not work
FOR /F "tokens=1,2* delims=: " %%A IN ('FIND /C "toto" c:\*.txt) DO (
IF %%A GTR 0 ( %%B >>resultat.txt )
)
Thank you for your help
Configuration: Windows 7 / Internet Explorer 9.0
I am facing a problem with my batch script.
Here is the process of the script that I would like to set up:
For all the files in c:\dossier\*.txt, search for the string "toto". If the file contains this string "toto", return the path of this file in c:\resultat.txt
Here is what I have tried but does not work
FOR /F "tokens=1,2* delims=: " %%A IN ('FIND /C "toto" c:\*.txt) DO (
IF %%A GTR 0 ( %%B >>resultat.txt )
)
Thank you for your help
Configuration: Windows 7 / Internet Explorer 9.0
3 answers
-
Hello,
You're not looking in the right folder:
FIND /C "toto" c:\*.txt -
Et can we replace "toto" with a previously declared variable?
SET VARIABLE=toto
FOR /F "tokens=1,2* delims=: " %%A IN ('FIND /C "%VARIABLE%" c:\*.txt) DO (
IF %%A GTR 0 ( %%B >>resultat.txt ) )
Thank you -
hello
for /f "tokens=1-3 delims=: " %%A in ('find /c "toto" C:\dossier\*.txt ') do if %%C NEQ 0 echo %%B >> c:\resultat.txt