Windows – copy/paste only certain files types in a directory

batch filecommand linecopy/pastewindows

Wondering if there is a script I could run in a .bat file that would allow me to copy only certain file types in a directory, and then paste them in another directory

Example of contents of directory: F:\testbatch\test1

test_01.tcs
test_02.tcs
test_03.tcs
garbagefile_01.txt
garbagefile_02.txt
nothing.rtf
test.tpl

Lets say I want to copy all .tpl & .tcs files in from F:\testbatch\test1 and paste them to:

F:\testbatch\test2

It should be noted that the destination directory F:\testbatch\test2 will already have some of the same files as the source folder, and I need these files to be overwritten.

So my question here is twofold:

1 – What command that I can put in a batch script will only copy certain types of files?

2 – How can I make sure when these files are copied & pasted that they will overwrite the existing files of the same name(s)?

EDIT I have tried:

xcopy "C:\Users\me\Desktop 3\123" *.bin "C:\Users\Jeff\Desktop 3\456" /y
xcopy "C:\Users\me\Desktop 3\123" *.tpl "C:\Users\Jeff\Desktop 3\456" /y

but nothing gets copied at all.

Running Windows 7 64 bit

Best Answer

What command that I can put in a batch script will only copy certain types of files?

Any command that accepts wildcards.

For example xcopy or robocopy.


How can I make sure when these files are copied they will overwrite existing files?

Use the xcopy /y (Suppress prompt to confirm overwriting a file) option.


I want to copy all .tpl and .tcs files from F:\testbatch\test1 to F:\testbatch\test2

Use the following commands

xcopy F:\testbatch\test1\*.tpl F:\testbatch\test2 /y
xcopy F:\testbatch\test1\*.tcs F:\testbatch\test2 /y

Why isn't this working?

I have tried:

xcopy "C:\Users\me\Desktop 3\123" *.bin "C:\Users\Fiver\Desktop 3\456" /y
xcopy "C:\Users\me\Desktop 3\123" *.tpl "C:\Users\Fiver\Desktop 3\456" /y

Your quotes are in the wrong place and you are missing a backslash.

The correct commands are:

xcopy "C:\Users\me\Desktop 3\123\*.bin" "C:\Users\Fiver\Desktop 3\456" /y
xcopy "C:\Users\me\Desktop 3\123\*.tpl" "C:\Users\Fiver\Desktop 3\456" /y

Further Reading

Related Question