I'm using the WHERE command as a search feature to find a specific file type within a group of folders, but I can't figure out how to export the results as a variable or something that I can reference to COPY the files that the WHICH command found. Any suggestions?
            Asked
            
        
        
            Active
            
        
            Viewed 146 times
        
    -2
            
            
         
    
    
        Aty'ai
        
- 37
- 7
1 Answers
0
            for /f "delims=" %%a in ('where command') do ECHO copy "%%a" "destination"
Where the echo simply shows the copy command required. remove the echo keyword to execute. I can't specify your destination.
Note that if the same filename appears more than once in the where list, you're likely to have the destination file overwritten.
This is a batch line - to execute directly from the prompt, use % in place of %%.
 
    
    
        Magoo
        
- 77,302
- 8
- 62
- 84
- 
                    The error message I get reads `The system cannot find the file WHERE.` This is the code i'm pasting into the command line: `for /f "delims=" %a in (WHERE /r "c:\users\myname\desktop\" print.txt /f) do copy "%a" "folderfolder"` – Aty'ai Jun 22 '17 at 18:35
- 
                    The `where command` must be within single-quotes as shown (ie put a single quote directly after the `(` and directly before `)` ). See `for /?` from the prompt for documentation. – Magoo Jun 22 '17 at 18:39