brewern
brewern

Reputation: 23

How do I create a batch file that will search all subdirectories for filetypes and copy them to a folder?

This is what I have:

for /R %i in (*.swf) do copy %i C:/testfolder/

I get the error "The system cannot find the file specified.

It's finding the .swf's just fine, but it's not copying them.

Upvotes: 2

Views: 3825

Answers (3)

Joey
Joey

Reputation: 354834

You probably want to put the argument to copy in quotes as well as use backslashes:

for /R %i in (*.swf) do copy "%i" C:\testfolder\

(though I seriously wonder why you're playing around in the root directory of the drive).

And remember to double the % if you're using that in a batch file.

Upvotes: 2

Boiler Bill
Boiler Bill

Reputation: 1960

You could use xcopy with the excludes argument (if you know what other types of files are present):

xcopy C:\sourcedir C:\destdir /EXCLUDE:excludes.txt /e

Where excludes.txt has a pattern of files not to copy on each line:

.svn
.obj
.js

Upvotes: 0

z-boss
z-boss

Reputation: 17618

Use Powershell.

See Example 1 — it is relative to your problem.

Upvotes: 0

Related Questions