Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Redirect result from FINDST (or FIND) to COPY, to copy certain files  (Read 20891 times)

0 Members and 1 Guest are viewing this topic.

Mickets

    Topic Starter


    Greenhorn
  • Hello, world!
  • Experience: Expert
  • OS: Windows XP
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.








Geek-9pm


    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: Redirect result from FINDST (or FIND) to COPY, to copy certain files
« Reply #1 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.


Salmon Trout

  • Guest
Re: Redirect result from FINDST (or FIND) to COPY, to copy certain files
« Reply #2 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\"

Squashman



    Specialist
  • Thanked: 134
  • Experience: Experienced
  • OS: Other
Re: Redirect result from FINDST (or FIND) to COPY, to copy certain files
« Reply #3 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!

Salmon Trout

  • Guest
Re: Redirect result from FINDST (or FIND) to COPY, to copy certain files
« Reply #4 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.



Venkat



    Rookie

    • Experience: Experienced
    • OS: Windows 7

     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....
    « Last Edit: May 27, 2014, 11:48:09 PM by Venkat »

    patio

    • Moderator


    • Genius
    • Maud' Dib
    • Thanked: 1769
      • Yes
    • Experience: Beginner
    • OS: Windows 7
    The Topic is almost 2 years old...
    Please start a new Topic if you need a solution...
    " Anyone who goes to a psychiatrist should have his head examined. "

    Venkat



      Rookie

      • Experience: Experienced
      • OS: Windows 7
      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:)

      patio

      • Moderator


      • Genius
      • Maud' Dib
      • Thanked: 1769
        • Yes
      • Experience: Beginner
      • OS: Windows 7
      ***sigh***
      " Anyone who goes to a psychiatrist should have his head examined. "