Here's another option. This will be much faster for large directories, as the above version runs the Find command for each file, and has to read the complete DirB.txt file for each file name it checks.
This will list all files that are found in both trees, all files that are in the First tree but not the Second, and all files that are in the Second tree but not the First.
Code:
@Echo Off
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: FindDup.cmd @Echo Off
:: Finds Duplicate and missing files in two directory trees
:: Written by TheOucaste
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
If [%1]==[] Goto _Usage
If [%2]==[] Goto _Usage
SetLocal EnableDelayedExpansion
Set _DirA=%~f1
Set _DirB=%~f2
If Not %_DirA:~-1%==\ Set _DirA=%_DirA%\
If Not %_DirB:~-1%==\ Set _DirB=%_DirB%\
If Not Exist "%_DirA%" (Echo %_DirA% does not exist)&Goto _Usage
If Not Exist "%_DirB%" (Echo %_DirB% does not exist)&Goto _Usage
:: set up info lines for each section of the report
Echo Files that are found in BOTH folders %_DirA% AND %_DirB%>_t0.txt
Echo.>>_t0.txt
Echo Files that are found in folder %_DirA% but NOT in folder %_DirB%>_t1.txt
Echo.>>_t1.txt
Echo Files that are found in folder %_DirB% but NOT in folder %_DirA%>_t2.txt
Echo.>>_t2.txt
If Exist _t3.txt Del /F /Q _t3.txt
:: Check root folders
For /F "Delims=" %%I In ('Dir /B /O:N /A-D "%_DirA%" 2^>Nul') Do If EXIST "%_DirB%%%I" (Echo %%I>>_t0.txt) Else (Echo %%I>>_t1.txt)
For /F "Delims=" %%I In ('Dir /B /O:N /A-D "%_DirB%" 2^>Nul') Do If NOT EXIST "%_DirA%%%I" Echo %%I>>_t2.txt
:: Check Subfolders of _DirA
For /F "Delims=" %%A In ('Dir /B /O:N /AD /S "%_DirA%" 2^>Nul') Do (
Set _CD=%%A
Call Set _CD=%%_CD:%_DirA%=%%
>>_t3.txt Echo !_CD!
For /F "Delims=" %%I In ('Dir /B /O:N /A-D "%_DirA%!_CD!" 2^>Nul') Do If EXIST "%_DirB%!_CD!\%%I" (Echo !_CD!\%%I >>_t0.txt) Else (Echo !_CD!\%%I>>_t1.txt)
For /F "Delims=" %%I In ('Dir /B /O:N /A-D "%_DirB%!_CD!" 2^>Nul') Do If NOT EXIST "%_DirA%!_CD!\%%I" Echo !_CD!\%%I>>_t2.txt
)
:: Check Subfolders of _DirB
For /F "Delims=" %%A In ('Dir /B /O:N /AD /S "%_DirB%"^|Findstr /I /V /G:_t3.txt') Do (
Set _CD=%%A
Call Set _CD=%%_CD:%_DirB%=%%
For /F "Delims=" %%I In ('Dir /B /O:N /A-D "%_DirB%!_CD!" 2^>Nul') Do If EXIST "%_DirA%!_CD!\%%I" (Echo !_CD!\%%I >>_t0.txt) Else (Echo !_CD!\%%I>>_t2.txt)
For /F "Delims=" %%I In ('Dir /B /O:N /A-D "%_DirA%!_CD!" 2^>Nul') Do If NOT EXIST "%_DirB%!_CD!\%%I" Echo !_CD!\%%I>>_t1.txt
)
:: write a separator line to end each section
For /L %%I In (0,1,2) Do Echo ---------------------------------------------------------------------->>_t%%I.txt
Copy /B _t0.txt+_t1.txt+_t2.txt duplicat.txt>Nul
:: Cleanup
For /L %%C In (0,1,3) Do (Del /F/Q _t%%C.txt)
Cls
More duplicat.txt
Echo Report saved as %~dp0duplicat.txt
Goto :EOF
:_Usage
Echo.
Echo %~n0 [drive:][path]Folder1 [[drive:]path]Folder2
Echo.
Echo. Compares two folder trees and Lists the differences
Echo. [drive:][path]Folder1 - First Folder Tree
Echo. [drive:][path]Folder2 - Second Folder Tree
Echo.
Echo. The folders must both exist. If Drive is not specified,
Echo. assumes path is relative to the current folder.
If you only want to list files that are in the First tree but not in the Second, this will do it:
Code:
@Echo Off
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: FindMiss.cmd @Echo Off
:: Finds files missing from a second directory tree
:: Written by TheOucaste
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
If [%1]==[] Goto _Usage
If [%2]==[] Goto _Usage
SetLocal EnableDelayedExpansion
Set _DirA=%~f1
Set _DirB=%~f2
If Not %_DirA:~-1%==\ Set _DirA=%_DirA%\
If Not %_DirB:~-1%==\ Set _DirB=%_DirB%\
If Not Exist "%_DirA%" (Echo %_DirA% does not exist)&Goto _Usage
If Not Exist "%_DirB%" (Echo %_DirB% does not exist)&Goto _Usage
:: set up info lines for each section of the report
Echo Files that are found in folder %_DirA% but NOT in folder %_DirB%>duplicat.txt
Echo.>>duplicat.txt
:: Check root folders
For /F "Delims=" %%I In ('Dir /B /O:N /A-D "%_DirA%" 2^>Nul') Do If NOT EXIST "%_DirB%%%I" Echo %%I>>duplicat.txt
:: Check Subfolders of _DirA
For /F "Delims=" %%A In ('Dir /B /O:N /AD /S "%_DirA%" 2^>Nul') Do (
Set _CD=%%A
Call Set _CD=%%_CD:%_DirA%=%%
For /F "Delims=" %%I In ('Dir /B /O:N /A-D "%_DirA%!_CD!" 2^>Nul') Do If NOT EXIST "%_DirB%!_CD!\%%I" Echo !_CD!\%%I>>duplicat.txt
)
:: Cleanup
Cls
More duplicat.txt
Echo Report saved as %~dp0duplicat.txt
Goto :EOF
:_Usage
Echo.
Echo %~n0 [drive:][path]Folder1 [[drive:]path]Folder2
Echo.
Echo. Compares two folder trees and Lists the files missing in the second
Echo. [drive:][path]Folder1 - First Folder Tree
Echo. [drive:][path]Folder2 - Second Folder Tree
Echo.
Echo. The folders must both exist. If Drive is not specified,
Echo. assumes path is relative to the current folder.
HTH
Jerry
__________________
Microsoft MVP - Windows Desktop Experience
Of course I know all the answers; I just don't always match the answers to the right questions.
Rated R for Violence -- When your PC flies through a window, that's violent, right?