Skip to content

Instantly share code, notes, and snippets.

@peplin
Created Jun 16, 2014
Embed
What would you like to do?
Perl script to find duplicate filenames
#!/usr/bin/perl -w
use File::Find;
my %files;
my @dirs;
foreach $argnum (0 .. $#ARGV) {
push(@dirs, $ARGV[$argnum]);
}
find(\&check_file, @dirs);
local $" = ", ";
foreach my $size (sort {$b <=> $a} keys %files) {
next unless @{$files{$size}} > 1;
my %names;
foreach my $path (@{$files{$size}}) {
$path =~ /([^\/]*$)/;
push @{$names{$1}}, $path;
}
foreach my $filename (keys %names) {
next unless @{$names{$filename}} > 1;
@{$names{$filename}}[0] =~ s/ /\\ /g;
@{$names{$filename}}[0] =~ s/'/\\'/g;
print @{$names{$filename}}, "\n";
#print @{$names{$filename}}[0], "\n";
#print @{$names{$filename}}[0], "\n";
}
}
sub check_file {
-f && push @{$files{(stat(_))[7]}}, $File::Find::name;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment