Skip to content

Instantly share code, notes, and snippets.

@uvtc
Last active December 30, 2015 13:49
Show Gist options
  • Save uvtc/7837784 to your computer and use it in GitHub Desktop.
Save uvtc/7837784 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use Modern::Perl;
use autodie qw/:all/;
use File::Copy;
my @tar_files = glob '*.tar'; # All the tar files in the curr dir.
unless (@tar_files) {
die "No tar files here. Exiting!\n";
}
for my $tar_file (@tar_files) {
my ($path, $row) = $tar_file =~ m/^LC8(\d{3})(\d{3})\d+LGN\.tar$/xms;
say "Found $tar_file, with path $path, and row $row";
my $dir = "p${path}_r${row}";
say " so, dir is $dir";
if (! -e $dir) {
say "$dir dir not found. Creating it...";
mkdir $dir;
}
move $tar_file, $dir;
chdir $dir;
system "tar", "xf", $tar_file;
# If you also want to delete the tar file, uncomment next line.
#unlink $tar_file;
chdir "..";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment