2

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

1
  • Have you tried the obvious command... copy? (i.e.: Copy F:\testbatch\test1\*.tpl F:\testbatch\test2). Copy also has an option for forcing overwrites without asking (see copy /?).. – Ƭᴇcʜιᴇ007 Apr 18 '17 at 21:17
4

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

0
1

There is no command that directly lets you pick multiple extensions types to copy files only with that extensions. The way I do it is create a batch file with multiple xcopy calls.

In your case, you want to create a batch file with the lines.

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

So the short answer is batch file is your friend.

-2

You may want to look into Robocopy. It has a multitude of different switches that can be used to get the results you want.

3
  • 2
    Rather than saying "Use this" - a good answer recommending a tool tells you how to use the tool. – Journeyman Geek Apr 18 '17 at 22:50
  • OK, noted. I had seen other comments that encourage questioners to do a modicum of work/research on their own before asking for help. Note that I had answered before the edit to the original question. Sometimes, a gentle push in the right direction is all that's needed. – Charles Burge Apr 18 '17 at 23:15
  • There's a specific meta post on this on meta which reflects the community consensus. The "do research" bit is more for questions than answers. – Journeyman Geek Apr 18 '17 at 23:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.