From bd9ce1578e0bb5150fd9142b6d8817c9b302478e Mon Sep 17 00:00:00 2001 From: Ward Wouts Date: Wed, 10 Jul 2002 09:08:46 +0000 Subject: [PATCH] newer stuff forgot to commit --- list_same/list_same | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/list_same/list_same b/list_same/list_same index dacfb65..b3ef499 100755 --- a/list_same/list_same +++ b/list_same/list_same @@ -1,5 +1,8 @@ #!/usr/bin/perl -w +# $Id$ +# $Source$ + # Generates a list of files in cur. dir which are actually the same # Compares size and MD5 checksum # Handy for cleaning up pictures like this: @@ -7,6 +10,8 @@ # wishlist: # - entering a list of file to check on the commandline +# - include escapes in output (spaces, brackets, etc) (optional) +# - option to ignore 0 length files # Changelog: @@ -18,7 +23,10 @@ # use MD5; instead of a shell call to md5 # some cleaning of code -use MD5; +use Digest::MD5; +use Getopt::Std; + +getopts('s'); opendir(DIR, ".") or die "can't open . $!"; while (defined($file = readdir(DIR))) { @@ -32,17 +40,24 @@ foreach (@filelist) { } } -foreach (keys %sizes) { - if (@{$sizes{$_}} > 1) { +foreach $size (keys %sizes) { + if (@{$sizes{$size}} > 1) { %md5s = (); - foreach (@{$sizes{$_}}) { + foreach (@{$sizes{$size}}) { push @{$md5s{&calc_md5($_)}}, $_; } - foreach (keys %md5s) { - if (@{$md5s{$_}} > 1) { - foreach (@{$md5s{$_}}) { print "$_ "; } + foreach $key (keys %md5s) { + if ((@{$md5s{$key}} > 1) and !$opt_s ) { + foreach (@{$md5s{$key}}) { print "$_ "; } print "\n"; } + elsif ((@{$md5s{$key}} > 1) and $opt_s ) { + @files = sort @{$md5s{$key}}; + for $i (1 .. $#files) { + chomp $files[$i]; + print "$files[$i]\n"; + } + } } } } @@ -61,7 +76,7 @@ sub get_size { sub calc_md5($file) { my ($file, $digest); $file = shift; - $md5 = new MD5; + $md5 = Digest::MD5->new; open FILE, "<$file" or die "couldn't open file: $!\n"; seek(FILE, 0, 0); $md5->reset;