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 | [reply] [d/l] |
<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 | [reply] [d/l] [select] |
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
| [reply] |
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
| [reply] |
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
| [reply] |
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 :) | [reply] [d/l] |
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.
| [reply] [d/l] [select] |