Click here for important information about

Find str in a file and if find then

February 7, 2011 at 13:43:00
Specs: Windows 7
I have a file "FileList.txt" from which I am reading a list of files in which I want to search for a string.
Let say file contains 5 file names, then I need to look in all these 5 files for a string "#void test".
If this string is not found in any of these files then delete the files name from File "FileList.txt" (which we used to find the names of the files)

The file name in FileList.txt is the 2 element after ',' so I used token 2 as I only wanted to read the 2 token.

for /f "tokens=2 delims=," %%i in (FileList.txt) do (
findstr /i "#void test" /F:somelocation\%%i

I don't know how to implement the second part, so that if "#void test" is not found, it will delete the particular file name from FileList.txt. Please help!

See More: Find str in a file and if find then

February 9, 2011 at 12:50:55
findstr /i "#void test" /F:somelocation\%%i

If it finds a match it returns errorcode 0 if does not then errorcode 1.

you can implement a if condition here, IF errorlevel 0 then write the filename to a tempfilename if errorlevel 1 then do not write the filename.

in the end of batch file, rename the tempfile to original filelist.txt

Subhash Chandra.

Report •

February 11, 2011 at 07:23:53
Could you please write some code referring to my code that I posted, I am very new to it. Thanks!

Report •
Related Solutions

Ask Question