Computer Hope

Microsoft => Microsoft DOS => Topic started by: Mickets on July 31, 2012, 10:41:54 AM

Title: Redirect result from FINDST (or FIND) to COPY, to copy certain files
Post by: Mickets on July 31, 2012, 10:41:54 AM
Hello,

I have a folder with hundreds of text files, but only a hand full have the keyword "glossary"in them. I need to find these files and copy them to another folder.

I can easily identify which files they are by using:

Code: [Select]
findstr /i /M "glossary:" *.txt
Where /I ignores case, and /M is so the result is only the file name.

Now all I need is to redirect this to a COPY command, to copy each found file to another folder.

I understand that by using the pipe, the result of one command will be redirected to the next command. So the result of FINDSTR will be sent to COPY. But COPY also expects the destination folder.

If I try

Code: [Select]
findstr /i /M "glossary:" *.txt | COPY /newfolder/
this won't work, because COPY expects the origin file and the destination folder, and above the destination folder is the first argument (and not the second).

I tried using

Code: [Select]
findstr /i /M "glossary:" *.txt | COPY %1 /newfolder/
but that didn't work either.

I think I may have to redirect to a temporary folder and then use that to copy to the new folder.

But I would imagine I could do it directly.

Ideas?

Thanks.







Title: Re: Redirect result from FINDST (or FIND) to COPY, to copy certain files
Post by: Geek-9pm on July 31, 2012, 11:21:51 AM
Quote
have a folder with hundreds of text files, but only a hand full have the keyword "glossary"in them. I need to find these files and copy them to another folder.
You don't need a batch file to copy a few files.
Instead of fretting about tough details, do what you can do. You can make the results into a list. Right? Then edit the list with Notepad and turn it into a batch file list instead of a loop.

Suppose I had some files with 'man' in the name. The I might get a list for text files like this:
Code: [Select]
pacman.txt
rayman.txt
mandate.txt
fatmanhop.txt
Using Notepad, I would put a # at the stat of each line and a $ at the end of the line.

Code: [Select]
#pacman.txt$
#rayman.txt$
#mandate.txt$
#fatmanhop.txt$
Even on a list of up to one hundred items, you can do this rather fast. Humans are like that. I am a human.
Next, I would tell notepad to replace every # with the word 'copy' with a space after it. Then back to top, replace every $ with a space and the target path.
When the above is done, I save may 'list.txt' files as 'list.bat' and run it as a bat file.
The time from concept to finish can be under half an hour.
Or, you can spend another day on loops and debugging.
The method I use is easier to visualize. Because you see it.
And you can do exceptions very easily.

Title: Re: Redirect result from FINDST (or FIND) to COPY, to copy certain files
Post by: Salmon Trout on July 31, 2012, 11:25:19 AM
one line of code...

Code: [Select]
for /f "delims=" %%A in ('findstr /i /M "glossary" *.txt') do copy "%%A" "\newfolder\"
Title: Re: Redirect result from FINDST (or FIND) to COPY, to copy certain files
Post by: Squashman on July 31, 2012, 11:26:39 AM
Code: [Select]
for /F "delims=" %%G in ('findstr /i /M "glossary:" *.txt') do copy "%%G" C:\NewFolder
Salmon beat me!
Title: Re: Redirect result from FINDST (or FIND) to COPY, to copy certain files
Post by: Salmon Trout on July 31, 2012, 11:37:38 AM
Salmon beat me!

But you gave the more faithful reproduction of the OP's wishes; I overlooked the colon after "glossary". Still, I expect the OP would have figured it out.


Title: Re: Redirect result from FINDST (or FIND) to COPY, to copy certain files
Post by: Venkat on May 27, 2014, 10:50:44 PM

 I want a batch code to  search a string exactly like "Interpretation (Interpret) Passed" from a set of HTML files locatind in folders and subfolders and send the files which contain that string to another folder. similarly i wanna even search "Interpretation (Interpret) Failed" and "Interpretation (Interpret) Incomplete" from html files and send to specified folder.
i tried with the code mentioned below:

@echo OFF
for /f "delims=" %%f in ('findstr /S/M /C:"Interpretation (Interpret) Failed" *.html') do copy "%%f" C:\\failedreports
for /f "delims=" %%f in ('findstr /S/M /C:"Interpretation (Interpret) Incomplete" *.html') do copy "%%f" C:\incompletereports
for /f "delims=" %%f in ('findstr /S/M "Interpretation (Interpret) Passed" *.html') do copy "%%f" C:\Passed

But this code doesn't work .... Any Help Pls??
 Its very urgent Pls help me out
Thanks in advance....
Title: Re: Redirect result from FINDST (or FIND) to COPY, to copy certain files
Post by: patio on May 28, 2014, 08:43:36 AM
The Topic is almost 2 years old...
Please start a new Topic if you need a solution...
Title: Re: Redirect result from FINDST (or FIND) to COPY, to copy certain files
Post by: Venkat on May 28, 2014, 09:39:50 AM
Hi patio, i already created a new post named-''To search and send "Interpretation (Interpret) Passed" Exactly from Html files'' since no one responded there posted here to see if some GURU replies,.....

If some1 knows the solution pls reply in that post mentioned above ....

Thank u in advance:)
Title: Re: Redirect result from FINDST (or FIND) to COPY, to copy certain files
Post by: patio on May 28, 2014, 12:09:29 PM
***sigh***