2

I am trying to create .bat file that syncs files and folders and so far I got up to this:

xcopy "C:\Users\user pc\Google Drive" "J:\Google drive offline backup" /d /e /f /h /i /j /k /r /s /y /z
for %%F in ("J:\Google drive offline backup\*") do if not exist "C:\Users\user pc\Google Drive\%%~nxF" del "%%~fF"

This basically copies only the newly created or modified files or directories that are from the source directory into the destination directory. Then, it deletes the files from the destination directory that does not exist in the source directory.

Now the problem is that I also like to know how to delete sub-directories in the destination directory that does not exist in the source directory.

Please don't bash my codes if it is badly made I am just a rookie in command prompt..

1

1 Answer 1

1

If your Windows is new enough (>= Windows XP), I recommend robocopy. For example:

robocopy "C:\Users\user pc\Google Drive" "J:\Google drive offline backup" /MIR

1
  • Wow, robocopy works exactly the way I wanted in my syncing program without the need to figure out all the nitty-gritty details to make it work like how I attempted to do above. Thanks! Jul 27, 2014 at 11:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .