in reply to Find duplicate files with exact same files noted
my @file_list; sub files_wanted { my $text = $File::Find::name; if ( -f ) { push @file_list, $text; } } #If you set a base directory above, you will need to change $directory to $base_directory.$directory. find(\&files_wanted,$directory); #This section creates a hash of arrays of files, with the hash keys be +ing filename.ext and the file +size in #parentheses. The raw file name is the entire path including the file +name. my %files; for my $raw_file (@file_list) { my @file_parts = split(/\//,$raw_file); my $file = pop @file_parts; my $file_size = -s $raw_file; push @{$files{"$file ($file_size bytes)"}}, $raw_file; }
Why tranverse the directory tree twice (and stat each file twice) when you only have to traverse it once:
my %files; find sub { if ( -f ) { push @{ $files{ "$_ (" . ( -s _ ) . " bytes)" } }, $File::Find +::name; } }, $directory;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Find duplicate files with exact same files noted
by Lady_Aleena (Priest) on Aug 17, 2010 at 19:18 UTC | |
by jwkrahn (Abbot) on Aug 17, 2010 at 20:31 UTC |