A neat xcopy trick

Windows has a command-line utility called xcopy, which it inherited from the good old DOS.   This utility is very useful when you need to copy a large number of files, especially if they are organized into an elaborate directory tree.  Out of the box, you can make xcopy copy only files that already exist in the destination location (just use the /U option); strangely, there is no obvious way to do the opposite — to only copy files that do not exist in the destination location.  DOStips.com to the rescue:

for /f %%a in ('xcopy "%source%" "%destination%" /L /Y') do (
  if not exist "%destination%.\%%~nxa" xcopy "%%a" "%destination%" /Y


Leave a Reply

Your email address will not be published. Required fields are marked *