Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > why empty zip files?

Reply
Thread Tools

why empty zip files?

 
 
Geoff Cox
Guest
Posts: n/a
 
      10-12-2003
Hello,

The following code creates zip files, each 22 kb in size, but the doc
which should be there isn't there ...any ideas why?

I can get code to work where I define the file to be zipped and the
name of the zip file but trying to go through the whole folder using
File::Find is not working ...

Cheers

Geoff

use warnings;
use strict;

use File::Find;
use Archive::Zip;

my $dir = 'd:/a-keep8/perl/test';

find ( sub {

my $name = $_;
print ("$name \n");
my $zip = new Archive::Zip;
$zip->writeToFileNamed($name . ".zip");

}, $dir);

 
Reply With Quote
 
 
 
 
Greg Bacon
Guest
Posts: n/a
 
      10-12-2003
In article <(E-Mail Removed)>,
Geoff Cox <(E-Mail Removed)> wrote:

: The following code creates zip files, each 22 kb in size, but the doc
: which should be there isn't there ...any ideas why?
:
: I can get code to work where I define the file to be zipped and the
: name of the zip file but trying to go through the whole folder using
: File::Find is not working ...

You need to tell the module to add the files to the archives. You
also want to skip directories:

#! perl

use warnings;
use strict;

use File::Find;
use Archive::Zip;

my $dir = 'd:/a-keep8/perl/test';

find sub {
my $name = $_;
return if -d;
print ("$name \n");
my $zip = new Archive::Zip;
$zip->addFile($name);
$zip->writeToFileNamed($name . ".zip");
} => $dir;

Hope this helps,
Greg
--
Anger is a gift.
-- rage against the machine
 
Reply With Quote
 
 
 
 
Geoff Cox
Guest
Posts: n/a
 
      10-12-2003
On Sun, 12 Oct 2003 11:29:40 -0000, http://www.velocityreviews.com/forums/(E-Mail Removed) (Greg Bacon)
wrote:

>In article <(E-Mail Removed)>,
> Geoff Cox <(E-Mail Removed)> wrote:
>
>: The following code creates zip files, each 22 kb in size, but the doc
>: which should be there isn't there ...any ideas why?
>:
>: I can get code to work where I define the file to be zipped and the
>: name of the zip file but trying to go through the whole folder using
>: File::Find is not working ...
>
>You need to tell the module to add the files to the archives. You
>also want to skip directories:


Greg,

Many thanks - all is well now with this code - now next problem!
Instead of using the name of the doc file as the name for the zip file
I would like to name the zip files, doc1.zip, doc2.zip etc

I am not clear where the loop goes?

Cheers

Geoff






> #! perl
>
> use warnings;
> use strict;
>
> use File::Find;
> use Archive::Zip;
>
> my $dir = 'd:/a-keep8/perl/test';
>
> find sub {
> my $name = $_;
> return if -d;
> print ("$name \n");
> my $zip = new Archive::Zip;
> $zip->addFile($name);
> $zip->writeToFileNamed($name . ".zip");
> } => $dir;
>
>Hope this helps,
>Greg


 
Reply With Quote
 
Lao Coon
Guest
Posts: n/a
 
      10-12-2003
Geoff Cox <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

> Instead of using the name of the doc file as the name for the zip file
> I would like to name the zip files, doc1.zip, doc2.zip etc
>
> I am not clear where the loop goes?


No loop. File::Find->find already iterates over all the files.
Just use a counter

....

my $count = 0;

find sub {
...
$count++;
$zip->writeToFileNamed("doc$count.zip");
...
} => $dir;


Lao
 
Reply With Quote
 
Geoff Cox
Guest
Posts: n/a
 
      10-12-2003
On Sun, 12 Oct 2003 13:55:20 +0200, Lao Coon <(E-Mail Removed)>
wrote:

>Geoff Cox <(E-Mail Removed)> wrote in
>news:(E-Mail Removed) :
>
>> Instead of using the name of the doc file as the name for the zip file
>> I would like to name the zip files, doc1.zip, doc2.zip etc
>>
>> I am not clear where the loop goes?

>
>No loop. File::Find->find already iterates over all the files.
>Just use a counter


Lao,

thanks - all is well again!

Cheers

Geoff

>
>...
>
>my $count = 0;
>
>find sub {
> ...
> $count++;
> $zip->writeToFileNamed("doc$count.zip");
> ...
>} => $dir;
>
>
>Lao


 
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
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Possibility to add a zip-file to a new zip-file with "add to zip" (right-click) ?? erikkie@casema.nl Computer Support 4 06-26-2006 12:18 AM
java.util.zip.ZipException: error in opening zip file hari_om@hotmail.com Java 0 05-03-2005 04:47 PM
java.util.zip - problem opening some legitimite me zip files Alex Hunsley Java 1 09-16-2004 02:06 PM



Advertisments