rrisal
asked on
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.loca l/New Folder"
xcopy "C:\New Folder" "\\Vcd061.vc.eaglecrk.loca l/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
@echo off
if "%3"=="" (
echo Syncing "C:\New Folder" with "\\Vcd061.vc.eaglecrk.loca
xcopy "C:\New Folder" "\\Vcd061.vc.eaglecrk.loca
)
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ROBOCOPY source dest /MIR
oh, 1 word of warning, be carefull, it WILL delete all files missing in source from dest and it will do it very quickly
Second the motion on robocopy. It seems to me you're reinventing the wheel doing it through batch script.