Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Archive::Zip on windows

Reply
Thread Tools

Archive::Zip on windows

 
 
ebm
Guest
Posts: n/a
 
      12-14-2007
I'm trying to have Archive::Zip zip a file on a windows systems. When
I create this file using the full path I end up with an empty zip
file.
Example:
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );

my $file = 'c:/TEST.xls';
my $zip = Archive::Zip->new();
print STDOUT "Adding $file\n";

$zip->addFile($file) or warn "Error adding file $file\n";
die "write error." if $zip->writeToFileNamed ("c:/file.zip") !=
AZ_OK;

__END__

I will end up with c:/file.zip but it will be empty. Now If I copy
the xls file to the same directory the script is running in it will be
zipped into c:/file.zip. It seems to be something to do with the C:\
part of the path it doesn't like. The pod file says something about
using Unix file formats..... Am i screwed or is there a way around
this.

Is there a way around this problem. This is apart of a larger script
so I can't hard code any file names. Any ideas?
 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      12-15-2007

Quoth ebm <(E-Mail Removed)>:
> I'm trying to have Archive::Zip zip a file on a windows systems. When
> I create this file using the full path I end up with an empty zip
> file.
> Example:
> use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
>
> my $file = 'c:/TEST.xls';
> my $zip = Archive::Zip->new();
> print STDOUT "Adding $file\n";
>
> $zip->addFile($file) or warn "Error adding file $file\n";
> die "write error." if $zip->writeToFileNamed ("c:/file.zip") !=
> AZ_OK;
>
> __END__
>
> I will end up with c:/file.zip but it will be empty. Now If I copy
> the xls file to the same directory the script is running in it will be
> zipped into c:/file.zip. It seems to be something to do with the C:\
> part of the path it doesn't like. The pod file says something about
> using Unix file formats..... Am i screwed or is there a way around
> this.


Try specifying a separate path to store the file as in the zip: a zip
member cannot have a volume specification. So:

$zip->addFile($file, 'TEST.xls');

or use File::Spec to split up the path and join it back together, sans
volume, as a Unix filespec.

Ben

 
Reply With Quote
 
 
 
 
Ron Bergin
Guest
Posts: n/a
 
      12-15-2007
On Dec 14, 5:12 pm, Ben Morrow <(E-Mail Removed)> wrote:
> Quoth ebm <(E-Mail Removed)>:
>
>
>
> > I'm trying to have Archive::Zip zip a file on a windows systems. When
> > I create this file using the full path I end up with an empty zip
> > file.
> > Example:
> > use Archive::Zip qw( :ERROR_CODES :CONSTANTS );

>
> > my $file = 'c:/TEST.xls';
> > my $zip = Archive::Zip->new();
> > print STDOUT "Adding $file\n";

>
> > $zip->addFile($file) or warn "Error adding file $file\n";
> > die "write error." if $zip->writeToFileNamed ("c:/file.zip") !=
> > AZ_OK;

>
> > __END__

>
> > I will end up with c:/file.zip but it will be empty. Now If I copy
> > the xls file to the same directory the script is running in it will be
> > zipped into c:/file.zip. It seems to be something to do with the C:\
> > part of the path it doesn't like. The pod file says something about
> > using Unix file formats..... Am i screwed or is there a way around
> > this.

I tested your code as well as a couple slight variations and they all
worked for me.
>
> Try specifying a separate path to store the file as in the zip: a zip
> member cannot have a volume specification. So:

That is not correct. The volume specification will be stripped from
the first parameter, but if you supply it in the optional second
parameter, it will be retained in the zip.
>
> $zip->addFile($file, 'TEST.xls');
>
> or use File::Spec to split up the path and join it back together, sans
> volume, as a Unix filespec.
>

The following test script worked for me and retained the volume spec
in the zip, without the need to use File::Spec.

The script was ran from and executed as D:/zipme.pl

use strict;
use warnings;
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );

my $file = 'c:/testing/test.pl';
print "Adding $file\n";

my $zip = Archive::Zip->new();

$zip->addFile($file, $file) or warn "Error adding file $file\n";

die "write error." if $zip->writeToFileNamed("d:/temp/file.zip") !=
AZ_OK;
 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      12-15-2007

Quoth Ron Bergin <(E-Mail Removed)>:
> On Dec 14, 5:12 pm, Ben Morrow <(E-Mail Removed)> wrote:
> >
> > Try specifying a separate path to store the file as in the zip: a zip
> > member cannot have a volume specification. So:

> That is not correct. The volume specification will be stripped from
> the first parameter, but if you supply it in the optional second
> parameter, it will be retained in the zip.


It's not a volume spec in that case, as zips use Unix filespecs. It's
just a directory called 'c:'. I've no idea what would happen if you
tried to extract such a zip under Win32.

Ben

 
Reply With Quote
 
Michele Dondi
Guest
Posts: n/a
 
      12-16-2007
On Sat, 15 Dec 2007 12:02:04 +0000, Ben Morrow <(E-Mail Removed)>
wrote:

>It's not a volume spec in that case, as zips use Unix filespecs. It's
>just a directory called 'c:'. I've no idea what would happen if you
>tried to extract such a zip under Win32.


C:\temp>zipme.pl c:\temp\win0.pl
Adding c:\temp\win0.pl

C:\temp>del win0.pl

C:\temp>unzip file.zip
Archive: file.zip
inflating: c_/temp/win0.pl

(With minimal modifications to zipme.pl and InfoZIP's unzip.)


Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
 
Reply With Quote
 
ebm
Guest
Posts: n/a
 
      12-17-2007
On Dec 14, 5:12 pm, Ben Morrow <(E-Mail Removed)> wrote:
> Quothebm<(E-Mail Removed)>:
>
>
>
> > I'm trying to have Archive::Zip zip a file on a windows systems. When
> > I create this file using the full path I end up with an empty zip
> > file.
> > Example:
> > use Archive::Zip qw( :ERROR_CODES :CONSTANTS );

>
> > my $file = 'c:/TEST.xls';
> > my $zip = Archive::Zip->new();
> > print STDOUT "Adding $file\n";

>
> > $zip->addFile($file) or warn "Error adding file $file\n";
> > die "write error." if $zip->writeToFileNamed ("c:/file.zip") !=
> > AZ_OK;

>
> > __END__

>
> > I will end up with c:/file.zip but it will be empty. Now If I copy
> > the xls file to the same directory the script is running in it will be
> > zipped into c:/file.zip. It seems to be something to do with the C:\
> > part of the path it doesn't like. The pod file says something about
> > using Unix file formats..... Am i screwed or is there a way around
> > this.

>
> Try specifying a separate path to store the file as in the zip: a zip
> member cannot have a volume specification. So:
>
> $zip->addFile($file, 'TEST.xls');
>
> or use File::Spec to split up the path and join it back together, sans
> volume, as a Unix filespec.
>
> Ben


Thanks for the help, I'll give it a try. I ended up doing a work
around where I copy the file to the same dir as the script. Zip the
cached file I just copied and output the the desired location.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
!Windows Live Mail replace Outlook Express on Windows XP and Windows Mail on Vista... Max Burke NZ Computing 8 05-18-2007 12:10 AM
Windows XP Home Connected to Windows XP Pro via TCP/IP Armstrong Wong Wireless Networking 1 11-25-2004 01:12 PM
wireless ad-hoc with Windows XP and Windows 2000 =?Utf-8?B?ZHVtbWthdWY=?= Wireless Networking 1 09-23-2004 11:34 AM
Windows XP laptop and Windows 2000 desktop won't communicate =?Utf-8?B?UmlmbGVtYW4=?= Wireless Networking 0 08-19-2004 03:35 AM



Advertisments