Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use xcopy to only copy files if they are newer?

I have many web applications in a Visual Studio solution.

All have the same post build command:

xcopy "$(TargetDir)*.dll" "D:\Project\bin" /i /d /y 

It would be useful to avoid replacing newer files with old ones (e.g. someone could accidentally add a reference to an old version of a DLL).

How can I use xcopy to replace old files only with newer DLL files generated by Visual Studio?

like image 489
Junior Mayhé Avatar asked Jul 13 '11 20:07

Junior Mayhé


People also ask

How do I use xcopy to copy only new files?

If you want to copy only new files or changed files, you can use xcopy command in batch script file on Windows system. /i /d /y parameters provide that copy only new files and changed files. These detect file modify time changes , but do not notice size changes.

How do I copy only the latest or updated files in PowerShell?

To copy only updated or newer files with PowerShell, we can use Copy-Item with some logic in the script that to check if the files exist on the destination folder if not then copy that file and if yes then compare the timestamp and copy the latest file.

Does xcopy Skip existing files?

xcopy cannot be configured to SKIP existing files, so you should copy using "robocopy".


1 Answers

From typing "help xcopy" at the command line:

/D:m-d-y     Copies files changed on or after the specified date.              If no date is given, copies only those files whose              source time is newer than the destination time. 

So you already are using xcopy to only replace old files with new ones. If that's not happening, you may have to swap the positions of the /i and /d switches.

like image 84
JAB Avatar answered Sep 20 '22 04:09

JAB