Skip to content

Instantly share code, notes, and snippets.

@AdamDimech
Created November 9, 2016 00:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdamDimech/cb8efd14c095d31e70deefa78f810fd1 to your computer and use it in GitHub Desktop.
Save AdamDimech/cb8efd14c095d31e70deefa78f810fd1 to your computer and use it in GitHub Desktop.
Perl Unzipping Utility
#!/usr/bin/perl
use strict;
use warnings;
package TidyUnzipper;
use strict;
use Archive::Zip qw(:ERROR_CODES :CONSTANTS);
use Exporter 'import';
our @EXPORT = qw(unzip);
# For Command-Line Options
my ($zip_file, $out_file, $filter) = @ARGV;
unzip($zip_file, $out_file, $filter) if scalar @ARGV;
1;
# Make file name string
my $shortname = fileparse($zip_file, qr/\Q.zip\E/);
# Unzip file into a new directory called zip_temp
sub Unzipper {
my ($zip_file, $out_file, $filter) = @_;
my $zip = Archive::Zip->new();
unless ( $zip->read( $zip_file ) == AZ_OK ) {
die 'Read error: The file could not be unzipped';
}
$zip->extractTree( '', 'zip_temp/' );
}
# Rename zip_temp
rename("zip_temp", $shortname);
# Explanation
use File::Basename;
use strict;
# Get full path in $path
my $filename = basename($zip_file);
# Print statement
print "The file $filename has been unzipped.\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment