Solved Issue with find string for subdirectories

April 7, 2012 at 23:21:03
Specs: Windows Vista
I am trying to use the find command on all .txt files in a folder and all of its subfolders. I am using something like:
FOR /R %a in (*.*) do FIND "string" %a *.txt >results.txt

This is working for the root directory, but will not not for any of the subdirectories.


See More: Issue with find string for subdirectories

Report •

✔ Best Answer
April 9, 2012 at 02:31:19
Change strategy: try the following

for /F "delims=" %a in ('dir /B /S *.txt') do @(find "string" "%a" 1>nul 2>&1 && find "string" "%a") >> result.log

The above works perfectly on my system under Windows Vista.


#1
April 8, 2012 at 03:06:47
for /R %a in (.) do find "string" %a \*.txt >results.txt

Report •

#2
April 8, 2012 at 13:53:12
I still can't get it to work for subdirectories. It just says file not found for any txt files thats not in the root directory, even though they contain they string

Report •

#3
April 8, 2012 at 14:32:54
The statement logs the results in result.txt stored in each subdirectory. Use as target file C:\results.log or the drive letter you want and suffix .log. It should work (don't miss the double >>)

for /R %a in (.) do find "string" %a \*.txt >> C:\results.log



Report •

Related Solutions

#4
April 8, 2012 at 15:00:17
I changed it to .\*,txt but it still doesn't work

I tried what you said but I only get access denied error.

On an iteration in a sub directory it does (new folder is a sub directory):
find "string" C:\Users\Playthius\Desktop\Descriptions\New Folder\test.txt .\*.txt 1>results.txt
But it still says file not found even thought it's there and contains "string"
Is the find syntax wrong?


Report •

#5
April 9, 2012 at 02:31:19
✔ Best Answer
Change strategy: try the following

for /F "delims=" %a in ('dir /B /S *.txt') do @(find "string" "%a" 1>nul 2>&1 && find "string" "%a") >> result.log

The above works perfectly on my system under Windows Vista.

Report •

Ask Question