in reply to Re: Bitwise comparision of files
in thread Bitwise comparision of files

Well , the script should read all the files from the first directory and all its subdirectories and compare to its corresponding files in second directory.The two directory name are command line arguments Result: FAIL - If atleast one file is not bitwise equal to the corresponding file in the second directory or the second directory has no file. Otherwise it is passed.

Replies are listed 'Best First'.
Re^3: Bitwise comparision of files
by Limbic~Region (Chancellor) on Feb 28, 2012 at 18:27 UTC
    kelly,
    Based on this explanation, you are going to want to take a look at File::Find. There are other modules on CPAN that try to make up for the horrendous call-back interface but the point is - don't try and walk the directory structure yourself - you will make a mistake.

    You are also going to want to take a look at File::Spec. There are a bunch of functions that will help you say things like chop off this portion of the path and replace it with this other path in order to determine if the file even exists in the other directory prior to comparing the actual file contents.

    You probably also want to take a look at Digest::MD5. It isn't a great choice for cryptographical reasons but in order to determine if two files are or are not the same, it has a really simple interface and should work just fine.

    If you want more help than that, you are going to have to show some more effort first.

    Cheers - L~R

      Thanks a lot guys, i will pursue the headsup . Basically my intention is not to simulate diff -r in Perl, rather the contents of the file bit-by-bit. Thanks once again.

        But that's what 'diff -r' does: compares the contents of two directory structures and reports any differences between the files, or files in one structure that are missing in the other. If you just want to know what files are different, without seeing the lines on which they are different, add the '-q' or '--brief' option.

        Aaron B.
        My Woefully Neglected Blog, where I occasionally mention Perl.

Re^3: Bitwise comparision of files
by JavaFan (Canon) on Feb 28, 2012 at 19:04 UTC
    Ah, so you want something else that what you first described. Hence, instead of using just diff, you should use diff -r, as in:
    diff -r directory1 directory2
    That's much faster than figuring out how to use File::Find, and doing all the comparison yourself.
Re^3: Bitwise comparision of files
by Riales (Hermit) on Feb 28, 2012 at 18:19 UTC
    If all you want to know is if there are any differences between the two directories, it might make sense to hash the tarballs of the directories and just see if the hashes match up.
Re^3: Bitwise comparision of files
by Marshall (Canon) on Feb 28, 2012 at 18:30 UTC
    The problem statement doesn't appear to be very well specified. Are you trying to enforce that say rootdir2 is a subset of rootdir1? - assuming that file structure is the same underneath both rootdirs? diff will compare two single files together. So now the problem appears to be how to select the two files to compare against?

    There are a number of recent posts about File::Find. Do a super search on that.