how do I search for one word through many files

I have to sort files depending on what they do. I have one word that I can filter with, but it means opening every file (3,500) and searching for this word.

How can I search through all these files quickly, with a script and separate the files containing the word to another folder ?

all the files open in a a text editor
Europa MacDonaldChief slayer of dragonsAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

OrenRozenCommented:
you can use the FINDSTR command to do the job.
0
Europa MacDonaldChief slayer of dragonsAuthor Commented:
ok, how do I do that ?
0
OrenRozenCommented:
the following command will search for the word FOUNDYOUin all files with the txt extension and when found it will save the name of the file in the filelist.txt

for /f "tokens=1 delims=:" %a in ('findstr "FOUNDYOU" *.txt') DO @echo %a >> filelist.txt

0
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

Europa MacDonaldChief slayer of dragonsAuthor Commented:
ok, is it possible to move the files straight to another directory or is that another command ?
0
OrenRozenCommented:
the following command will search for the word FOUNDYOUin all files with the txt extension and when found it will move the file to X:\myfiles\ folder

for /f "tokens=1 delims=:" %a in ('findstr "FOUNDYOU" *.txt') DO @move %a X:\myfiles\
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Europa MacDonaldChief slayer of dragonsAuthor Commented:
that has moved about 800 but I have lots of

the system can not find the file specified
and
the syntax of the command is incorrect

and there are still files in the original folder that are the type I want to detect and move
0
Bill PrewCommented:
You might need quotes as in:

for /f "tokens=1 delims=:" %a in ('findstr "FOUNDYOU" *.txt') DO @move "%a" "X:\myfiles\"

~bp
0
OrenRozenCommented:
are all the files located in the same folder?
0
OrenRozenCommented:
billprew is correct.
it will solve your problem if some of the files have spaces.
0
Europa MacDonaldChief slayer of dragonsAuthor Commented:
yes they are all in the same folder. will try that solution now
0
Europa MacDonaldChief slayer of dragonsAuthor Commented:
that time all I got was

the system can not find the file specified

all files are of the same type
0
Europa MacDonaldChief slayer of dragonsAuthor Commented:
but it moved another 400 files :-)
0
OrenRozenCommented:
do you still have the following issue ?

the system can not find the file specified
and
the syntax of the command is incorrect
0
Europa MacDonaldChief slayer of dragonsAuthor Commented:
all I get now is

the system cannot find the file specified

I am using *.mq4, all files are of this type

and the second solution moved another 400 files
0
Bill PrewCommented:
I suspect you have now moved all files that contain the string, you're done.

The problem is likely occuring due to FINDSTR now returning "FINDSTR: Cannot open *.xxxxxxxxxxxx" and the FOR parsing that as a filename result, and tossing an error since "findstr" is not a valid file.

~bp
0
Europa MacDonaldChief slayer of dragonsAuthor Commented:
Im just going to copy all the files already moved to another directory and test it again
0
Europa MacDonaldChief slayer of dragonsAuthor Commented:
that seems to have done the trick, thanks very much guys
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows OS

From novice to tech pro — start learning today.