Only copy new files with batch script

Posted by Dark Training on March 6, 2009 tags: | batch | windows

So you already know that you can use xcopy /u to copy files that already exist, but what about files that DONT already exist. In this scenario you are trying to copy only new files using a bat script.


It's actually not too hard at all, just use the /d switch when using xcopy. The /d switch will limit copy operations to a date but if you dont specify any date it will just grab any newer files and wont overwrite the older files, here is what it would look like if you were trying to move from a backup to a partial restore directory

xcopy C:\backup\ C:\restore\ /d /s /r /y


In the example above I tell the xcopy command to only copy new files, including empty directories (/s), we are going to overwrite any read only files (/r) and we are not going to be prompted to overwrite an existing file (/y).