PDA

View Full Version : Perl: Unzip a file


DanS
05-08-1999, 06:31 PM
Is there a script to unzip a file with an extension .zip?[nbsp][nbsp]Is a .gz file the same format as .zip?

Thanks all.

Deb
05-08-1999, 06:35 PM
They both compress files... but not in the same format... each requires their way of doing things... for telnet users this thread explains how to uncompress the files http://www.aota.net/ubb/Forum3/HTML/000290.html also if you do a serch for 'telnet zip' in the forums there is quite a bit of info.

For users of things like winzip there are ways to make it work for quite a few different types of compression formats...just depends what you are using etc...

Deb

DanS
05-08-1999, 06:46 PM
Thanks Deb![nbsp][nbsp]I was wanting to uncompress a batch of zip files from w/in a perl script.[nbsp][nbsp]Do you know of any way to do that?[nbsp][nbsp]Is there a way to give a unix command w/in a perl script?

DanS
05-08-1999, 09:09 PM
I suppose I could set up an sh script to:

1) run a perl script fetching each file;
2) execute an unzip on each of them; and
3) call a continue perl script.

Would this work, or is there a simpler way?

Terra
05-08-1999, 10:58 PM
$man Compress::Zlib

;)

--
Terra
--Perl==99 different complex ways to do 1 simple thing--
FutureQuest

DanS
05-09-1999, 12:14 AM
You're golden...

DanS
05-10-1999, 11:37 AM
Terra:[nbsp][nbsp]Do you know of any place where they have examples to this module?[nbsp][nbsp]I took a look at the man file, modified the "inflate" example for my needs.[nbsp][nbsp]It *should* work, but doesn't.[nbsp][nbsp]It successfully initializes inflate, but when I feed it the input string, it keeps returning -3 on $status with null output.

I did a ton of web searches and found nothing.

Thanks in advance for your help.

Terra
05-10-1999, 08:35 PM
1 of 2 choices...

Download that module directly from CPAN and look through the test parts '$make test'...

OR if your really adventerous, down load the actual cpan program and look through it's source...[nbsp][nbsp]It uses the Compress::Zlib library extensively...

--
Terra
--What do you want to smash today?--
FutureQuest

DanS
05-10-1999, 11:23 PM
Thanks Terra.[nbsp][nbsp]It was a good idea to download the cpan program.[nbsp][nbsp]It gave me several good ideas.[nbsp][nbsp]Oddly, I don't think it uses compress::zlib.[nbsp][nbsp]Rather, it uses the system command together with the unzip executable (that is if we are talking cpan.pm).

I think that if using system is good enough for CPAN, it's good enough for me. :)

Thanks for your help in working this through.

Terra
05-11-1999, 01:50 AM
Trust me, cpan.pm uses Compress::Zlib... ;)

--
Terra
--Trust No One--
FutureQuest

DanS
05-11-1999, 12:32 PM
OK, OK, if we're getting technical, CPAN does use Compress::Zlib, but not to unzip a .zip file.[nbsp][nbsp]Rather, it uses the following subroutine:


sub unzip_me {
[nbsp][nbsp][nbsp][nbsp]my($self,$local_file) = @_;
[nbsp][nbsp][nbsp][nbsp]$self->{archived} = "zip";
[nbsp][nbsp][nbsp][nbsp]my $system = "$CPAN::Config->{unzip} $local_file";
[nbsp][nbsp][nbsp][nbsp]if (system($system) == 0) {
[nbsp][nbsp][nbsp][nbsp][nbsp]$self->{unwrapped} = "YES";
[nbsp][nbsp][nbsp][nbsp]} else {
[nbsp][nbsp][nbsp][nbsp][nbsp]$self->{unwrapped} = "NO";
[nbsp][nbsp][nbsp][nbsp]}
}


Don't worry, I trust you ;)