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?
1 Answer
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 %%.
2 Comments
Aty'ai
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"Magoo
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.