Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Archive::Zip Period Problem

by CodeJunkie (Monk)
on Apr 03, 2003 at 09:49 UTC ( #247717=perlquestion: print w/replies, xml ) Need Help??

CodeJunkie has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I have a slightly silly problem with archive::zip

I want to have a program that just unzips all files in an archive to the current directory. I managed to adapt a script from the docs for this purpose, and it works, but for some reason all the extracted files have a '.' character infront of them!!!! Weird! So my files look like this:

.myfile.cgi

#!c:\perl\bin\perl use strict; use CGI::Carp 'fatalsToBrowser'; use CGI qw( :standard :html3 ); use Archive::Zip; my $form=new CGI; my ($submit)=param('submit'); print "Content-type:text/html\n\n"; if ($submit) { print "Unzipping Archive...<br/>"; my $zip = Archive::Zip->new(); my $zipName = "webauction3.4.zip"; my $status = $zip->read( $zipName ); die "Read of $zipName failed\n" if $status != AZ_OK; $zip->extractTree(); } else { print "<form name=\"install\" method=\"post\" action=\"install.cgi\" +> <input type=\"submit\" name=\"submit\" value=\"Install >>\"/> </form>"; }

I'm not sure why this is happening, can someone help me? I could always rename all the files after extracting, but this is not the neatest way of doing it i'm sure.

cheers,
Tom

Replies are listed 'Best First'.
Re: Archive::Zip Period Problem
by Anonymous Monk on Apr 03, 2003 at 11:32 UTC
    I think extractTree() somehow gets confused with extracting to the current directory "." and forgets to append the path separator. Try:
    $zip->extractTree("", ".\\");
    worked for me.

      cheers mate, that fixed it!

      $zip->extractTree("", ".\\");

      Actually that fixed it on my windows Perl, but when I put it on a remote unix/linux machine it changed all the files to

      .\file.cgi

      Which was even worse cause my ftp program couldn't see the files so I had to manually rename them using command prompt ftp... fun fun fun

        $zip->extractTree("", "./"); should work on both OSes.

        Makeshifts last the longest.

Re: Archive::Zip Period Problem
by hacker (Priest) on Apr 03, 2003 at 11:47 UTC
    What about using getcwd() and friends from Cwd?
    use strict; use Cwd; # Remember to untaint $dir my $dir = getcwd();

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://247717]
Approved by robartes
Front-paged by Courage
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2020-05-25 11:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (145 votes). Check out past polls.

    Notices?