Synchronizing two networked folders

Labored whole day, just to come up with a batch file using XCOPY to do it.

In the case of synchronizing removed files, I used for loop, but the big trick was the setlocal EnableDelayedExpansion command. Without it, the variable seems to be non-dynamic.

I supposed I have to settle with it now anyhow, it is just not worth the time, despite the fact that I cannot remove hidden files, chinese character filenames, if they somehow exist on the backup folder. Nonetheless, at least all my Work files can now be backed up by a click on the batch file shortcut.

Sample:

@echo off
echo Syncrhonizing with Backup Network Drive...
setlocal EnableDelayedExpansion
FOR /F "delims=" %%a in ('dir /b /a /s "\\networkedpc\Work"') Do (set poi=%%a && if not exist G:\Work\!poi:~22! (echo "Deleting %%a..." && del /Q %%a))
endlocal

XCOPY "G:\Work" "\\networkedpc\Work" /D /I /S /Y
echo ...Synchronization Complete###
pause

This entry was posted in Technical. Bookmark the permalink.

Leave a Reply

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

ERROR: si-captcha.php plugin: GD image support not detected in PHP!

Contact your web host and ask them to enable GD image support for PHP.

ERROR: si-captcha.php plugin: imagepng function not detected in PHP!

Contact your web host and ask them to enable imagepng for PHP.

This site uses Akismet to reduce spam. Learn how your comment data is processed.