Push up to cloud git

This commit is contained in:
Gwyn 2026-01-12 22:39:05 -05:00
commit 2c80264f34
2 changed files with 38 additions and 0 deletions

38
mvcopies.pl Normal file
View file

@ -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!";