Computing.Net > Forums > Programming > Perl Archive::zip

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Perl Archive::zip

Reply to Message Icon

Name: mongar
Date: December 27, 2005 at 12:21:35 Pacific
OS: win2000/2003
CPU/Ram: 500mb
Comment:

i am new in perl & i am trying to zip a file in a directory c:\scripts\1.txt using the module Archive::zip this is my script what am i doing wrong
$_="c:\/scripts\/1.txt";
use Archive::Zip;
$zip = Archive::Zip->new($_);

the errors that i get are :

format error: file is too short
at C:/Perl/site/lib/Archive/Zip.pm line 1057
Archive::Zip::Archive::_findEndOfCentralDirectory('Archive::Zip::Archive
=HASH(0x225288)', 'IO::File=GLOB(0x1c14858)') called at C:/Perl/site/lib/Archive
/Zip.pm line 966
Archive::Zip::Archive::readFromFileHandle('Archive::Zip::Archive=HASH(0x
225288)', 'IO::File=GLOB(0x1c14858)', 'c:/scripts/1111.TXT') called at C:/Perl/s
ite/lib/Archive/Zip.pm line 940
Archive::Zip::Archive::read('Archive::Zip::Archive=HASH(0x225288)', 'c:/
scripts/1111.TXT') called at C:/Perl/site/lib/Archive/Zip.pm line 523
Archive::Zip::Archive::new('Archive::Zip::Archive', 'c:/scripts/1111.TXT
') called at C:/Perl/site/lib/Archive/Zip.pm line 220
Archive::Zip::new('Archive::Zip', 'c:/scripts/1111.TXT') called at 2.pl
line 3

and if i try to zip another file like news.png
i get the error
format error: can't find EOCD signature
at C:/Perl/site/lib/Archive/Zip.pm line 1090
Archive::Zip::Archive::_findEndOfCentralDirectory('Archive::Zip::Archive
=HASH(0x225288)', 'IO::File=GLOB(0x1c14858)') called at C:/Perl/site/lib/Archive
/Zip.pm line 966
Archive::Zip::Archive::readFromFileHandle('Archive::Zip::Archive=HASH(0x
225288)', 'IO::File=GLOB(0x1c14858)', 'c:/scripts/news.png') called at C:/Perl/s
ite/lib/Archive/Zip.pm line 940
Archive::Zip::Archive::read('Archive::Zip::Archive=HASH(0x225288)', 'c:/
scripts/news.png') called at C:/Perl/site/lib/Archive/Zip.pm line 523
Archive::Zip::Archive::new('Archive::Zip::Archive', 'c:/scripts/news.png
') called at C:/Perl/site/lib/Archive/Zip.pm line 220
Archive::Zip::new('Archive::Zip', 'c:/scripts/news.png') called at 2.pl
line 3




Sponsored Link
Ads by Google

Response Number 1
Name: ghostdog
Date: December 27, 2005 at 19:28:16 Pacific
Reply:

just a suggestion,
for a start, you can try change the $_="c:\...."
declaration to something like

my $filetozip = q(c:\scripts\1.txt);
and try again

btw what's the full perl code that you have written.? From your post, you have just 3 lines of code, and the last one is just initializing a new object.


0

Response Number 2
Name: mongar
Date: December 30, 2005 at 06:41:25 Pacific
Reply:

here is my code!!! i run your suggestion but got an error "format error: file is too short" , all i want is to use the Archive::zip module to zip my files thats located in c:/server/logfiles/k11/2344/

code starts here..

use File::Find;
$dir1="c:/server/logfiles/";
print "$dir1\n";
find(\&wanted, $dir1);
sub wanted {

if (/^ex/) {
$w=`date /T`;
#print $w;
@tt= split /(\d\d)/,$w;
#foreach (@tt) { print "$_\n" }
#print"@tt[3]";
#print"@tt[1]";
#print"@tt[7]";


@rr=split /(\d\d)/,$_;


#print "@rr[1]\n";###03

#print "@rr[3]\n";###12
#print "@rr[5]\n";###06

if (@rr[1]!=@tt[3] or @rr[3]!=@tt[1] or @rr[5]!=@tt[7]) {

@arr=split('/',"$File::Find::dir/$_");




#use Archive::Zip;
#$zip = Archive::Zip->new($_);


system("PKZIP.EXE $_.zip $_");



use Net::FTP;
$ftp = Net::FTP->new("localhost", Debug => 0);
print $ftp->message;
$ftp->login("anonymous",'');
print $ftp->message;
if ($ftp->cwd("@arr[3]"))
{print"@arr[3] exist\n";}

else {$ftp->mkdir("@arr[3]");

$ftp->cwd("@arr[3]"); }
print $ftp->message;
$ftp->binary;
print $ftp->message;
$ftp->put("$File::Find::dir/$_.zip");
print $ftp->message;
$ftp->quit;

system("del
$_.zip");
#system("del $_");
}

}









}


0

Response Number 3
Name: FishMonger
Date: December 30, 2005 at 08:52:20 Pacific
Reply:

I see a number of things that need to be fixed. But first, I have 2 questions.

If the files to be zipped are in "c:/server/logfiles/k11/2344/", why do you start the search from "c:/server/logfiles", which is 2 levels above the desired directory?

What is the exact format of your filenames? I know you're using a date structure something like "x30x12x05.txt", but in order to help, I'll need to know the exact format.

Due to the way Justin is parsing our post submissions, posting code in this forum is a joke. I can post a cleaned up and corrected script, but it would be best if I email it to you.


0

Response Number 4
Name: FishMonger
Date: December 30, 2005 at 10:14:14 Pacific
Reply:

Here's an example script that uses Archive::Zip to create a zip file containing all of your logfiles. Once I know your exact filename format I can add the code to only put the desired files in the zip.

#!perl -w

use strict;
use File::Find;
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );

my $dir = 'c:/server/logfiles';
my $zip = Archive::Zip->new();
my $zipped;

$zipped = $zip->addDirectory( $dir );
$zipped->desiredCompressionMethod( COMPRESSION_DEFLATED );
find(\&zip_file, $dir);
die 'write error' unless $zip->writeToFileNamed( 'logs.zip' ) == AZ_OK;

sub zip_file {
$zipped = $zip->addFile( $File::Find::name );
}


0

Response Number 5
Name: mongar
Date: December 31, 2005 at 11:44:33 Pacific
Reply:

First Answer:
I start the search from "c:/server/logfiles"
cause i dont know which folders are under
"c:/server/logfiles" there could be alot of directory in the same structure like "c:/server/logfiles/k11/2344" .
Second Answer:
the exact format of my filenames is :
ex051028.log .
i dont need to zip the file thats on the date i am running the script only the day before.
my email is
shcohen2002@yahoo.com
by the way thanks alot



0

Related Posts

See More



Response Number 6
Name: FishMonger
Date: December 31, 2005 at 12:13:34 Pacific
Reply:

There's a much easier method for calculating yesterday's date and testing for the filename. Use the strftime fuction from the POSIX module.

For example:

$filename = strftime("ex%Y%m%d.log", localtime(time-86400));

if (-e $filename) {
# zip the file
}

I'll send you an updated script when I have a little more free time. BTW, are you looking for and zipping only 1 file or are there multiple files in various directories?


0

Response Number 7
Name: mongar
Date: December 31, 2005 at 13:49:08 Pacific
Reply:

you make my life easier
i wanted to say but i forgot
there are multiple files in various directories and i need to zip one file seperatly as you can see in the script i am uploading each file to an ftp in a special directory.
on the script you sent me all the files were zipped to a directory.
now i broke my mind over it and i cant succeed zipping 1 losy file.
its seem that i dont quite understand the syntax .

well isnt it right to zip 1 file

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

my $file = 'D:\Internet\LogFiles\1.txt';
my $zip = Archive::Zip->new();
my $zipped;
$zipped = $zip->addFile( $file );


0

Response Number 8
Name: FishMonger
Date: December 31, 2005 at 14:04:58 Pacific
Reply:

Check your email. I sent you an updated script at the same time you were making your last post.

You can zip the files individually and ftp each one separately, but that's not the most efficient approach. I'd need to think about this, but I'd probably create 1 zip file and then after the ftp, unzip the file and all files should expand to their proper locations.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Echo blank line from batc... dos loop



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Perl Archive::zip

ising archive::zip www.computing.net/answers/programming/ising-archivezip/19461.html

Count number of files in zip archive www.computing.net/answers/programming/count-number-of-files-in-zip-archive/20254.html

help with unziiping file archives!! www.computing.net/answers/programming/help-with-unziiping-file-archives/8120.html