Is there an easy way to copy a file if it contains a text string

Oct 11, 2013
4
0
In ANT it's easy to do that and it's the one function over the years that I've really wished Take Command had.
 
May 20, 2008
11,845
120
Syracuse, NY, USA
Do you mean something like this?

Code:
ffind /t"text string" file > nul
if %_? == 0 copy file ...

On one line

Code:
if %@exec[ffind /t"text string" file > nul] == 0 copy file ...
 
Oct 11, 2013
4
0
Yeah, that should work if I put it in a For loop so I can copy all the files in a directory that contain the text string. Thanks! :) I'll give it a try and let you know.
 

samintz

Scott Mintz
May 20, 2008
1,533
21
Solon, OH, USA
If the goal is to copy a bunch of files then an easier solution would be be to use the file names that ffind spits out.
Code:
do f in /p ffind /b /c /t"text string" * (copy %f ...)
You can create an alias for that or a function.
Code:
alias tcopy=`do f in /p ffind /b /c /t%1 %2 (copy %f %3)`
tcopy "test string" * dest_folder
 
Oct 11, 2013
4
0
Thanks guys! Excellent advice! I just used the do f etc to find and copy all the PDFs created by a particular user to find the one he said had an incorrect format. It was a lot easier to open up 11 PDFs rather than several hundred. Of course I could have just used the windows explorer search function for that, but next I plan on using it in a script to automatically find logs with certain errors in our printing software.