-2

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?

0

1 Answer 1

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 %%.

Sign up to request clarification or add additional context in comments.

2 Comments

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"
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.