Batch scripting is a text file containing a series of commands intended to be executed by the command interpreter. Much like a unix / linux shell script, the purpose of a batch script is to sequentially process a series of commands.

Tags | | |

Only copy new files with batch script

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).



Comments

Feel free to leave a comment or question

Name: (Optional but appreciated):

Comment:

Use [code] [/code] for code block style



Security Code: