hackdaddy has asked for the wisdom of the Perl Monks concerning the following question:

Are there any directory comparison tools written in Perl?

I am currently using dircmp on Solaris, but this does not compare the uid, gid, size, and permissions.

I would like to be able to compare checksums, uid, gid, size, and permissions recursively between two directories. Are there any Perl or Unix tools that currently do this? Thanks!

Replies are listed 'Best First'.
Re: Recursive Directory Comparison Tools
by kvale (Monsignor) on Aug 08, 2002 at 23:22 UTC
    I don't know of any modules for you particular problem, but I would recommend looking at File::DirSync. Synchronization may not be what you are looking for, but the code used for directory comparison is probably just what you are looking for.
    use File::DirSync; my $dirsync = new File::DirSync { verbose => 1, nocache => 1, localmode => 1, }; $dirsync->ignore("CVS"); $dirsync->rebuild( $from ); # and / or $dirsync->dirsync( $from, $to );

    -Mark

Re: Recursive Directory Comparison Tools
by aufrank (Pilgrim) on Aug 08, 2002 at 22:00 UTC
    <pull leg>

    you might want to look at one of our most popular nodes, that fellow asked a very similar question and became quite famous for it. sadly, he isn't seen much around here anymore...

    </pull leg>
    --au

      This is not an invitation for a flame war.

      There is a dircmp class in the Python library that provides a comprehensive comparison of two directories. Without having to rewrite this in Perl, are there any comparable modules or classes written in Perl?

      http://www.python.org/doc/current/lib/dircmp-objects.html

        I don't have a definitive answer for you, but I can say that IO::Dir and DirHandle look promising. You might also want to look at some of the modules in the file:: series, especially the ones included in perl 5.8. Sorry I can't be of more help, I've just got no experience with the subject.

        --au

Re: Recursive Directory Comparison Tools
by PetaMem (Priest) on Aug 09, 2002 at 08:07 UTC
    Hi,

    look at my diffy node. It should give you a pretty good start for something that individually fits your needs.

    I have tested it on Linux only, but it should run on any unix. To make a portable version for Win32 see the discussion for this node.

    Bye
     PetaMem

Re: Recursive Directory Comparison Tools
by kschwab (Vicar) on Aug 09, 2002 at 13:39 UTC
    This isn't a very perlish answer, but have a look at rsync.

    It's mainly used to synchronize between two hosts, but it has a '-n' flag that will just do the comparison. There's also a perl interface over here.

    I find this quite handy, since it can compare 2 directory trees on the same host, or two directory trees on different hosts. A quick comparison that will look at ownership, group, ,permissions, modification times, sizes, checksums, etc, is as easy as:

    rsync -nav /some/dir/ /other/dir/
    The trailing slashes mean something, and don't forget the -n, or it will synchronize the two directories :)
Re: Recursive Directory Comparison Tools
by mp (Deacon) on Sep 03, 2002 at 17:30 UTC
    I've done this type of thing before by using File::Find along with Digest::MD5 and stat() to recursively walk through a directory and create a "file status" file for both directories. The file status files can be sorted by filename, then "diff"-ed to show differences between the two directory trees. The format of the file status file looked something like this: (pipe-delimited).
    dir1/path/to/file1|MD5checksum_of_file_content|last_modified_time|perm +s|... dir1/path/to/file2|MD5checksum_of_file_content|last_modified_time|perm +s|... ...
    To get started easily, you can run 'find2perl dir1' to build the code for you, then edit the contents of sub wanted to print the various attributes that you want compared.

    If you need to do directory synchronization, you may also find unison to be useful.