How to compare 2 directories?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • stamatis32
    New Member
    • May 2007
    • 3

    How to compare 2 directories?

    Hello everybody,
    i want to make a prog to compare the contents of 2 dirs.
    You can compare easily 2 files, but how this happend with dirs. I am very confused, i dont know where to start from, can anyone help? I search on many books but i haven't found anything similar
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Originally posted by stamatis32
    Hello everybody,
    i want to make a prog to compare the contents of 2 dirs.
    You can compare easily 2 files, but how this happend with dirs. I am very confused, i dont know where to start from, can anyone help? I search on many books but i haven't found anything similar
    Have you have to decide what you are going to compare about them - size, contents, location, etc...? How you will get that information will depend on the OS you are using, but doing so shouldn't be that difficult - it's more a matter of deciding how to save the information in the easiest manner that will allow comparison.

    Comment

    • stamatis32
      New Member
      • May 2007
      • 3

      #3
      OS windows, Borland C++
      The name and the size of the containing files is what i want to check, not dirs name and size
      ex.
      DIR1 DIR2
      file1 -1KB file1 -2KB
      file2 -1KB file2 -1KB

      file2 have the same name an size on both Dirs,
      file1 have the same name but different size, this is what i want

      "sorry for my bad english"
      and thanks in advance

      Comment

      • sicarie
        Recognized Expert Specialist
        • Nov 2006
        • 4677

        #4
        Originally posted by stamatis32
        OS windows, Borland C++
        The name and the size of the containing files is what i want to check, not dirs name and size
        ex.
        DIR1 DIR2
        file1 -1KB file1 -2KB
        file2 -1KB file2 -1KB

        file2 have the same name an size on both Dirs,
        file1 have the same name but different size, this is what i want

        "sorry for my bad english"
        and thanks in advance
        Ok, so have you developed an algorithm for this?

        Comment

        • stamatis32
          New Member
          • May 2007
          • 3

          #5
          my problem is that i dont know how to open the dir not what to do with the rest comparisons

          Comment

          • Banfa
            Recognized Expert Expert
            • Feb 2006
            • 9067

            #6
            Look up FindFirstFile and its brethren FindFirstFileEx , FindNextFile and FindClose.

            Basically when doing a directory comparison a file can have 1 of 4 statuses

            1. File in both directories, and the same
            2. File in both directories, but different
            3. File only in first directory
            4. File only in second directory

            To detect all of those states you will need to list the files in both directories and compare (names and sizes by what you have already said) and then assign a status to each file.

            Comment

            Working...