Archive::Zip on windows

E

ebm

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?
 
B

Ben Morrow

Quoth ebm said:
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
 
R

Ron Bergin

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;
 
B

Ben Morrow

Quoth Ron Bergin said:
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
 
M

Michele Dondi

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
 
E

ebm

Quothebm<[email protected]>:






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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,821
Messages
2,569,725
Members
45,511
Latest member
Osiris-Team

Latest Threads

Top