why empty zip files?

G

Geoff Cox

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);
 
G

Greg Bacon

: 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
 
G

Geoff Cox

: 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
 
L

Lao Coon

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
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top