silow
silow

Reputation: 4306

copying folder content

I'm writing a batch script and need to copy the content of a certain folder to another folder.

For example I have the folder

source/
  file1.txt 
  file2.txt 
  file3.txt 

and I have files in a destination folder. How do I copy the contents of source into destination so the final destination would look like this

destination/
  existing1.txt
  existing2.txt
  file1.txt 
  file2.txt 
  file3.txt 

I tried xcopy but can't quite get it right.

Upvotes: 1

Views: 183

Answers (2)

Stephen
Stephen

Reputation: 121

Using wildcards as mentioned above you can easily copy the contents from one file to another.

For example if your source folder and destination folder are on your desktop you could have the following: (substituting the "YOURNAME" with your PC or laptop's name)

@echo off > *.txt

setLocal DisableDelayedExpansion

set dest="C:\Documents and Settings\YOURNAME\Desktop\destination"

xcopy "C:\Documents and Settings\YOURNAME\Desktop\source\*.txt" %dest% /E /I

Upvotes: 1

Oded
Oded

Reputation: 499272

Just use wildcards:

xcopy source\*.* destination\*.*

Upvotes: 2

Related Questions