DOS Batch: Mirror Contents of One Directory to Another with Prompt using Robocopy


/ Published in: DOS Batch
Save to your folder(s)

This batch mirrors the contents of one directory to another using Robocopy. It will display a list of what is being mirrored before prompting the user for confirmation on the mirror.

WARNING: Robocopy's /MIR switch that is used in this batch WILL remove any destination objects not present in the source directory


Copy this code and paste it in your HTML
  1. :: mirrorp.bat
  2. :: Mirror contents of one directory to another with prompt using Robocopy
  3. ::
  4. :: Usage examples:
  5. :: mirrorp C:\source \\server\share\destination
  6. :: mirrorp D:\mydirectory "C:\directory name with spaces"
  7. ::
  8. :: Author: Karl Horky
  9. :: Date: 15 April 2010
  10. :: Updated: 03 July 2010 (added /IS /IT /COPYALL to get NTFS permissions and date time tweaks - Thanks Chris)
  11.  
  12. @echo off
  13.  
  14. if ""%1"" == """" ( goto :error )
  15. if ""%2"" == """" ( goto :error )
  16.  
  17. SET _source=%1
  18. SET _dest=%2
  19.  
  20. robocopy %_source% %_dest% /MIR /IS /IT /COPYALL /L
  21. set /p ans=Run mirror? [y/n]^>
  22. if "%ans%" == "y" ( goto :copytotest ) else ( goto :donothing )
  23. :copytotest
  24. echo Copying...
  25. robocopy %_source% %_dest% /MIR /IS /IT /COPYALL /NJS /NJH
  26. goto :eof
  27. :donothing
  28. echo No action taken.
  29. goto :eof
  30. :error
  31. echo Incorrect command usage.
  32. echo Usage: mirrorp C:\source \\server\share\destination

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.