• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 419
  • Last Modified:

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
0
Europa MacDonald
Asked:
Europa MacDonald
  • 9
  • 6
  • 2
2 Solutions
 
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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 9
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now