Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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