Results 1 to 6 of 6

Thread: Batch file to compare directories

  1. #1
    Join Date
    Mar 2010
    Posts
    184

    Batch file to compare directories

    Hello,
    I am trying to compare two directories, also if it is possible then I will compare the the files in the those directories,but the first problem is to compare the two directories, and the result that is the difference between the two directories must go to another file. Is this possible, if it is then please let me know. Thanks in advance.
    www.techarena.in

  2. #2
    Join Date
    Dec 2009
    Posts
    296

    Re: Batch file to compare directories

    Hello,
    Even I am trying a similar kind of a program. Consider that there are two folder A and B respectively. all the file in the B directory are present in the A directory, but there are some other files in the A directory. How do I sort out these files
    I have do this code till now
    Code:
    for %%F in (*.*) do dir ..\A\%%F /b >> ..\test.txt
    So, if you have any idea about this then please help me with this. Thank you for your help.

  3. #3
    Join Date
    Nov 2009
    Posts
    347

    Re: Batch file to compare directories

    Hello,
    You can try something like this , if you need
    Code:
    fc /L c:\filemon.txt c:\dos.txt > c:\test.txt
    If you just want to copy the text file then this code will work and if you want more that this you have to add some more code to it. Also you can use the error codes such as xxxcp16 etc. If you need to copy the files differently then you need to use the IFN in your code. Hope this information will help you. If you have any more queries regarding this topic then do post back.

  4. #4
    Join Date
    Nov 2009
    Posts
    583

    Re: Batch file to compare directories

    Hello,
    I do no think this should be really hard to do. If you have some programming basic then you can do this easily. A few months I had written a code which would delete the duplicated files or entries from the directory tree list. But to do a program like this your code should be or rather is heavenly based on the the services like the REXX/CRC etc.. As you need to match the size of the file and some of their properties. So, if goes hard without this code. I guess you have understood what i am trying to explain.

  5. #5
    Join Date
    Nov 2009
    Posts
    356

    Re: Batch file to compare directories

    Hello,
    I had a similar kind of problem a few days before, but I had wrote a code which solved all of my queries
    Here is the code which i am talking about
    Code:
    diff -u <dir1> <dir2> > <path to difference>/somefile.txt
    See, if this part of code works for you. This is not the full code, but this is the important line in the code. I think this should solve your problem. Try out this and if you have any queries related to this code then post back with the error you get.

  6. #6
    Join Date
    Nov 2009
    Posts
    446

    Re: Batch file to compare directories

    Hello,
    You can use the following batch script
    Code:
    Echo Files that are found in BOTH folders %dA% AND %dB% >b.txt
    Echo. >>b.txt
    findstr /G:dA.txt dB.txt >>b.txt
    echo ------------------------------------- >>b.txt
    
    
    Echo Files that are found in folder %dA% but NOT in folder %dB% >AnotinB.txt
    Echo. >>AnotinB.txt
    find /V /C "this_is_an_absurd_string" dB.txt >nln.txt
    for /f "tokens=3 delims= " %%B in (nln.txt) do set /A maxnum=%%B
    
    for /F  "tokens=* delims= " %%A in (dA.txt) do (
    find /V /C "%%A" dB.txt >nln.txt
    for /f "tokens=3 delims= " %%B in (nln.txt) do set /A foundnum=%%B
    if %maxnum%==!foundnum! echo %%A >>AnotinB.txt
    )
    echo ------------------------------------- >>AnotinB.txt
    
    
    Echo Files that are found in folder %dB% but NOT in folder %dA% >bnA.txt
    Echo. >>bnA.txt
    find /V /C "this_is_an_absurd_string" dA.txt >nln.txt
    for /f "tokens=3 delims= " %%B in (nln.txt) do set /A maxnum=%%B
    
    for /F "tokens=* delims= " %%A in (dB.txt) do (
    find /V /C "%%A" dA.txt >nln.txt
    for /f "tokens=3 delims= " %%B in (nln.txt) do set /A foundnum=%%B
    if %maxnum%==!foundnum! echo %%A >>bnA.txt
    )
    echo. >>bnA.txt
    echo ------------------------------------- >>bnA.txt
    
    copy /B b.txt+AnotinB.txt+bnA.txt dupli.txt >nul
    more dupli.txt
    
    for %%A in (dA.txt dB.txt b.txt AnotinB.txt bnA.txt nln.txt) do (
    if exist %%A del %%A
    )

Similar Threads

  1. Difficulties with reciprocal access to file directories in Linux
    By Ander K in forum Networking & Security
    Replies: 4
    Last Post: 19-01-2011, 04:48 PM
  2. Windows Batch file to output directory names and size to txt file
    By m2thearkus in forum Software Development
    Replies: 6
    Last Post: 16-07-2010, 12:04 AM
  3. Dos batch file to sort files based on file names.
    By Jon Osborn in forum Windows Server Help
    Replies: 9
    Last Post: 17-06-2009, 11:06 AM
  4. Replies: 3
    Last Post: 12-03-2009, 12:56 PM
  5. Batch file to list directories, export to CSV
    By chickenfriedsteak in forum Windows Server Help
    Replies: 1
    Last Post: 16-02-2009, 08:35 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,010,187.74134 seconds with 17 queries