#!/usr/bin/perl -w use strict; use warnings; my @files = glob "*.*"; my @tar_files = glob '*.tar.gz'; # All the tar files in the curr dir. my @jpg_files = glob '*.jpg'; # All the .jpg files in the curr dir. unless (@files) { die "No files here. Exiting!\n"; } for my $tar_file (@tar_files) { my ($path, $row) = $tar_file =~ m/^LC8(\d{3})(\d{3})\d+LGN\d\d\.tar.gz$/xms; print "Found $tar_file, with path $path, and row $row\n"; my $dir = "p${path}_r${row}"; print "...so... dir is /$dir\n"; #if (! -e $dir) { #print "$dir dir not found..."; #} { system ("mv $tar_file /data2/jennb/landsat8/antarctica/$dir") == 0 or die "can't move file!"; print "moved $tar_file to /$dir\n"; } { chdir "/data2/jennb/landsat8/antarctica/$dir" or die "can't cd to /$dir !\n"; print "...moving to /$dir...\n"; system ("pwd"); } { print "current contents: "; system ("ls"); print "...untaring... please wait...\n"; system ("tar -xzvf $tar_file --wildcards '*B8*'") == 0 or die "unpacking of $tar_file failed!\n"; print "printing new contents...\n"; system ("ls"); print "...moving on...\n"; } { chdir "/data2/jennb/landsat8/downloads"; print "...listing remaining contents in /downloads...\n"; system ("ls"); } } print "tar files done...now jpgs...\n"; for my $jpg_file (@jpg_files) { my ($path, $row) = $jpg_file =~ m/^LC8(\d{3})(\d{3})\d+LGN\d\d\.jpg$/xms; print "Found $jpg_file, with path $path, and row $row\n"; my $dir = "p${path}_r${row}"; print "...so... dir is /$dir\n"; system ("mv $jpg_file /data2/jennb/landsat8/antarctica/$dir") == 0 or die "Failed to move $jpg_file\n"; print "Moved jpg to /$dir\n"; } print "process complete!\n";