Comparing Two Folders and its Subfolder batch file

前端 未结 4 1572
渐次进展
渐次进展 2021-02-09 00:27

I have two folders that contain all the same files and subfolders, but the conents inside each file may have changed. I want to write a batch file that will search through each

4条回答
  •  余生分开走
    2021-02-09 00:34

    Here is another way to accomplish the task. Set the variables Folder1 and Folder2 to the full path of the folders you want to compare and run the batch file.

    Output:

    Dup – the file exists in both folders and are identical.

    Dif - the file exists in both folders but the content of the files are different.

    New – The file exists in one folder but not the other.

    @Echo Off
    SetLocal EnableDelayedExpansion
    
    Set "Folder1=%UserProfile%\Desktop\Test Folder1"
    Set "Folder2=%UserProfile%\Desktop\Test Folder2"
    
    For /R "%Folder1%" %%x In (*.*) Do (
    
        Set "FullPath=%%x"
        Set "RelPath=!FullPath:%Folder1%=!"
    
        If Exist "%Folder2%!RelPath!" (
          >Nul 2>&1 FC /b "%Folder1%!RelPath!" "%Folder2%!RelPath!" && (
           Echo Dup - %%x
          )||(
           Echo Dif - %%x
          )
        ) Else (
          Echo New - %%x
        )
    )
    
    For /R "%Folder2%" %%x In (*.*) Do (
    
        Set "FullPath=%%x"
        Set "RelPath=!FullPath:%Folder2%=!"
    
        If Not Exist "%Folder1%!RelPath!" (
          Echo New - %%x
        )
    )
    

提交回复
热议问题