Sync and deleting using batch file

I have this batch file. It syns the directories and files from source to destination. I'm trying to modify it so that if a file exist in destination that does not exists in source that file should be deleted off the destination machine in addition to the sync of source and destination which the below command will do. Any help would be greatly appreciated.

@echo off  
 
if "%3"=="" (  
echo Syncing "C:\New Folder" with "\\Vcd061.vc.eaglecrk.local/New Folder"  
xcopy "C:\New Folder" "\\Vcd061.vc.eaglecrk.local/New Folder" /d /i /y /e
)  
 
for /D %%d in (%2\\*) do (  
if not exist "%1\\%%~nd" (  
echo Deleting directory %%~nd  
rd "%%d" /s /q  
)  
)  
 
for %%f in (%2\\*) do (  
if not exist "%1\\%%~nf%%~xf" (  
echo Deleting file %%~nf%%~xf  
del "%%f"  
)  
)  
 
for /D %%d in (%1\\*) do call Batch3.bat "%1\\%%~nd" "%2\\%%~nd" 0  


rrisalAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
dlangrConnect With a Mentor Commented:
i would use robocopy: http://www.ss64.com/nt/robocopy.html
0
 
dlangrCommented:
ROBOCOPY source dest /MIR
0
 
dlangrCommented:
oh, 1 word of warning, be carefull, it WILL delete all files missing in source from dest and it will do it very quickly
0
 
ShineOnCommented:
Second the motion on robocopy.  It seems to me you're reinventing the wheel doing it through batch script.
0
All Courses

From novice to tech pro — start learning today.