COPY function in FOR loop (batch) -


i working on batch script synchronize 2 folders. mean synchronize is: script compare each file of each folder , keep recent 1 in each folder. smart backup program.

here part of code having trouble (the whole script can found here):

for /d /r %drivepath% %%d in (*) (   set currentdrivefolderpath=%%d   if not exist "%devicepath%!currentdrivefolderpath:~%drivelength%!" (     mkdir "%devicepath%!currentdrivefolderpath:~%drivelength%!"   )   %%f in (*.*) (     set currentfile=%%f     if exist "%devicepath%!currentdrivefolderpath:~%drivelength%!!currentfile!" (       set currentdrivefile="!currentdrivefolderpath!\!currentfile!"       set currentdevicefile="%devicepath%!currentdrivefolderpath:~%drivelength%!!currentfile!"       call:comparemodifieddate !currentdrivefile! !currentdevicefile!       if !recent! == file1 (         copy /y !currentdrivefile! !currentdevicefile!       ) else if !recent! == file2 (         copy /y !currentdevicefile! !currentdrivefile!       )     ) else (       set source       copy /y !currentdrivefile! !currentdevicefile!     )   ) )  /d /r %devicepath% %%d in (*) (   set currentdevicefolderpath=%%d   if not exist %drivepath%!currentdevicefolderpath:~%devicelength%! (     mkdir "%drivepath%!currentdevicefolderpath:~%devicelength%!"     %%f in (*.*) (       set currentfile=%%f       if not exist "%drivepath%!currentdevicefolderpath:~%devicelength%!!currentfile!" (         copy /y !currentdrivefile! !currentdevicefile!       )     )   ) ) 

my question is: what can call copy function inside loop source , destination paths changing each time?

i'm not going try figure out code - painful - knowing there simpler solution.

i believe need 2 simple xcopy statements, 1 in each direction, /d option both folder hierarchies synchronize recent versions of each file in each. there more flesh out, think should on way. use robocopy in similar fashion - gives lots more options , more robust, more complex syntax want.

assume root paths d:\path1 , e:\path2

xcopy d:\path1 e:\path2 /e /d /y xcopy e:\path2 d:\path1 /e /d /y 

i've done rudimentary testing, , appears work, i've not done rigorous testing. sure run plenty of tests make sure haven't missed something.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -