Search code examples
batch-filecmdbeyondcomparebeyondcompare3

Compare two windows folders for differences and post them out to a new folder(Beyond compare)


I have the following scenario

Folder 1
 -Folder a
      -File1.txt
      -Img1.png
 -Folder b
      -File2.txt
      -Img2.png

Folder 2
 -Folder a
      -File1.txt (File 1 modified)
      -Img1.png   (No change)
 -Folder b
      -File3.txt (New file added)
      -Img2.png  (no change)

Basically I want the output folder to have the following files(modified or added in the original structure, with the structure preserved)

OutputFolder
  -Folder a
       -File1.txt
  -Folder b 
       -File3.txt

I am trying to use the Beyond Compare Command line to do this, but I cant find any arguments to suit and I dont want to loop over all files(too many files) for changes manually or use SVN. Any other tool/script I could use to achieve this?


Solution

  • if the changes are only in the "Folder 2"-Structure and Folder 1 will always be untuched, i got it to work with:

    @ECHO OFF
    SETLOCAL ENABLEDELAYEDEXPANSION
    FOR /F "TOKENS=2,* DELIMS=  " %%A IN ('ROBOCOPY "Folder 2" "Folder 1" /MIR /XX /NDL /NJH /NJS /L') DO (
      SET tmpFolder=%%~dpB
      SET tmpFolder=!tmpFolder:Folder 2=OutputFolder!
      XCOPY "%%~B" "!tmpFolder!" /E /F /H /R /C
    )
    ENDLOCAL
    

    Robocopy will only list the changes between folder 2 and folder 1, the for loop will copy the files to the "outputfolder", keeping the folder-structure