I'd like a batch script in Windows with which I can copy one directory to another. If this directory already exists, and then for each file that already exists in both with the same name and location, it should be overwritten, if it does not exists, it should just be added.
In the end it should be a batch script to which I can pass 2 arguments, source & destination.
This question is related to
windows
batch-file
Have you considered using the "xcopy" command?
The xcopy command will do all that for you.
Just use xcopy /y source destination
Try this:
xcopy %1 %2 /y /e
The %1
and %2
are the source and destination arguments you pass to the batch file. i.e. C:\MyBatchFile.bat C:\CopyMe D:\ToHere
It seems that the latest function for this in windows 7 is robocopy.
Usage example:
robocopy <source> <destination> /e /xf <file to exclude> <another file>
/e copies subdirectories including empty ones, /xf excludes certain files from being copied.
More options here: http://technet.microsoft.com/en-us/library/cc733145(v=ws.10).aspx
Source: Stackoverflow.com