in reply to Re: extracting self-extracting pkzipped files with Archive::Zip
in thread extracting self-extracting pkzipped files with Archive::Zip
Many thanks to the maintainer and author of the Archive::Zip module. Ned Konz was very helpful.#!/usr/bin/perl -w use Archive::Zip qw( :CONSTANTS ); use POSIX; use File::Basename; use File::Copy; use strict; ############################################################## # # $Author: $ # $Date: $ # $Locker: $ # # When - 28 Mar 2001 # Purpose - (sensored) # ## MANY thanks to Ned Konz. He is the author and maintainer ## of the Archive::Zip module. He was integral in assisting ## me in getting this blasted thing to work the way I needed ## it to work. ## # # History: # # TODO: # ############################################################## my $sandbox = "/tmp/sandbox"; opendir(D,"$sandbox") or warn("Could not open $sandbox\n"); my @FILES = grep(/(\.EXE)/,readdir(D)) or die("Read error in $sandbox +at line " . __LINE__ . "\n");; close(D); chdir("$sandbox"); for ( @FILES ) { my $file = $_ ; my $unzip = Archive::Zip->new("$file"); warn("Read error in $file at line " . __LINE__ . "!\n") if ( ! def +ined($unzip) ) and next; foreach my $member ( $unzip->members() ) { print "**** File to be extracted: " . $member->fileName() . "\n"; warn("Hmm, there was a problem\n") if ( !defined($member->extractToFileNamed( "$sandbox/" . $memb +er->fileName() )) ); } } 0
The above code successfully unzips files without directories in the archive. So this will only work on archives that are meant to be unzipped in the destination directory which the archive would currently be located in.
The way I have the script written is it will only find files that are named *.EXE because the project that I am working with has files named *.EXE that are pkzip self-extractable archives. I am only working in a Unix environment (solaris 7) and I know for a fact where these files are coming from and what they should be. If they fail, I will contact the provisioner of these files to redistribute them to my company.
That all being said, I again appreciate the assistance I received here today.
- Jim
Edit 2001-03-28 by tye to replace <pre> with <code>
|
|---|