commit 2c80264f3456881ef1a5d9e5221b2f1df4528fbf Author: Gwyn Date: Mon Jan 12 22:39:05 2026 -0500 Push up to cloud git diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/mvcopies.pl b/mvcopies.pl new file mode 100644 index 0000000..9457aef --- /dev/null +++ b/mvcopies.pl @@ -0,0 +1,38 @@ +#! /bin/perl +use strict; +use warnings; +use File::Spec; +use File::Path qw(make_path); +use Digest::MD5; +use File::Copy qw(move); +use feature 'say'; +use File::Basename; + +my $src = shift @ARGV or die "Usage: $0 dir\n"; +die "'$src' is not readable" unless -d $src and -r $src; +my $dup_dir = File::Spec->catdir($src, "copies"); +make_path($dup_dir) unless -d $dup_dir; +opendir(my $d, $src) or die $!; +my @unsorted_stuff = grep { -f File::Spec->catfile($src, $_) } readdir($d); +closedir($d); + +my %fried; +map { + my $file = $_; + my $path = File::Spec->catfile($src, $file); + open(my $potato, '<', $path) or warn "I couldn't open '$file'\n"; + binmode($potato); + my $hash = Digest::MD5->new->addfile($potato)->hexdigest; + close($potato); + if ($fried{$hash}) { + my $dest = File::Spec->catfile($dup_dir, $file); + my $i = 1; + my ($name,$dir,$ext) = fileparse($file, qr/\.[^.]*/); + $dest = File::Spec->catfile($dup_dir, "${name}_$i$ext") while -e $dest and $i++; + move($path, $dest) or warn $!; + say "Duplicate $file is moved to $dest"; + } else { + $fried{$hash} = 1; + } +} @unsorted_stuff; +say "All copies in $src have been moved to $dup_dir!";