View Single Post
Old 06-16-2009, 02:44 PM   #4 (permalink)
TheOutcaste
TSF Enthusiast
 
TheOutcaste's Avatar
 
Join Date: Mar 2009
Location: Portland, OR
Posts: 821
OS: MS-Dos 6.22 - Win7


Re: Creating batch file to Check Directories

That won't work, as the files will contain the full path. Since dirA and dirB are different, it will indicate that all the files in dirA are not in dirB
For example, if test1.txt is in dirA, this will check to see if C:\dirA\test1.txt is found in the listing for dirB. It won't be, as test1.txt will be listed as C:\dirB\test1.txt

You need to remove the root folder from the string you are checking:
Code:
@Echo Off
SetLocal EnableDelayedExpansion
Set dirA=%~1
Set dirB=%~2

Dir /B /O /S "%dirA%">dirA.txt
Dir /B /O /S "%dirB%">dirB.txt

Echo.>>AnotinB.txt
Find /V /C "this_is_an_absurd_string" dirB.txt>numlines.txt
For /F "tokens=3 delims= " %%B In (numlines.txt) Do Set /A maxnum=%%B

For /F "tokens=*" %%A In (dirA.txt) Do (
Set _FN=%%A
Call Set _FN=%%_FN:%dirA%=%%
Find /V /C "!_FN!" dirB.txt>numlines.txt
For /F "tokens=3 delims= " %%B In (numlines.txt) Do Set /A foundnum=%%B
If %maxnum%==!foundnum! Echo %%A>>AnotinB.txt
)
more AnotinB.txt

For %%A In (dirA.txt dirB.txt numlines.txt) Do If Exist %%A Del %%A
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?

Last edited by TheOutcaste; 06-16-2009 at 02:52 PM. Reason: typo
TheOutcaste is offline   Reply With Quote