Created
June 16, 2014 13:27
-
-
Save peplin/4f2570e046b5bc144352 to your computer and use it in GitHub Desktop.
Perl script to find duplicate filenames
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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