Solved how to find and move files that contain an exact phrase

October 23, 2015 at 08:00:49
Specs: Windows 7
i'd like to write a batch file that parses through a directory and moves any file which match a particular phrase in its contents (eg "hello world")

there is a findstr example here that works great for a single word, but i can't get it to work for the life of me for more than one word to search a phrase. any help please?


See More: how to find and move files that contain an exact phrase

Report •


#1
October 23, 2015 at 08:16:23
You are not alone. You might care to look at this Google search while you are waiting for a programmer:

https://www.google.co.uk/#q=batch+f...

Always pop back and let us know the outcome - thanks


Report •

#2
October 23, 2015 at 08:33:32
✔ Best Answer
Untested:
for /f "delims=" %%a in ('findstr /m /c:"a phrase" *') do move "%%a" "somewhere"

How To Ask Questions The Smart Way


Report •

#3
October 23, 2015 at 09:09:00
thank you! i'm not sure why, but when i use that logic i don't get any results. a single word works fine. does this only work for files encoded in a certain way? would it work with utf-8 files or unicode?

Report •

Related Solutions

#4
October 23, 2015 at 09:12:27
nevermind. it works!! i had to convert all the files to a 1252 codepage and voila.

thank you everyone for the quick help!


Report •

#5
October 23, 2015 at 09:55:26
If you're dealing with different encodings, you might want to look in to PowerShell, where you can specify it.
dir | 
Select-String "a phrase" -List -Encoding utf8 | 
foreach { move $_.Path "somewhere" }

How To Ask Questions The Smart Way


Report •


Ask Question