Skip to content

Commit

Permalink
Added move-dropbox-photos.pl
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed May 4, 2023
1 parent c6da11d commit d84a3ff
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions move-dropbox-photos.pl
@@ -0,0 +1,54 @@
#!/usr/bin/perl -w

use warnings;
use strict;

sub usage {
die("USAGE: $0 <srcpath> <dstpath>\n");
}


my $srcpath = undef;
my $dstpath = undef;

foreach (@ARGV) {
$srcpath = $_, next if not defined $srcpath;
$dstpath = $_, next if not defined $dstpath;
usage();
}

usage() if not defined $srcpath;
usage() if not defined $dstpath;

opendir(my $dirp, $srcpath) or die("Couldn't opendir '$srcpath': $!\n");
while (readdir($dirp)) {
my $fname = $_;
my $fullpath = "$srcpath/$fname";
next if not -f $fullpath;
if (/\A(\d\d\d\d)\-(\d\d)\-(\d\d) \d\d\.\d\d\.\d\d/) {
my $year = $1;
my $month = $2;
my $day = $3;
mkdir("$dstpath");
mkdir("$dstpath/$year");
mkdir("$dstpath/$year/$month");
my $fulldstpath = "$dstpath/$year/$month/$fname";
die("uhoh, '$fulldstpath' already exists!\n") if ( -f $fulldstpath );
#print("mv '$fullpath' '$fulldstpath'\n");
system("mv '$fullpath' '$fulldstpath'");
if ($? == -1) {
die("failed to execute 'mv': $!\n");
} elsif ($? & 127) {
my $sig = ($? & 127);
die("'mv' died with signal $sig\n");
} else {
my $rc = ($? >> 8);
if ($rc != 0) {
die("'mv' failed with exit code $rc\n");
}
}
}
}
closedir($dirp);

exit(0);

0 comments on commit d84a3ff

Please sign in to comment.