why empty zip files?

Discussion in 'Perl Misc' started by Geoff Cox, Oct 12, 2003.

  1. Geoff Cox

    Geoff Cox Guest

    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);
     
    Geoff Cox, Oct 12, 2003
    #1
    1. Advertising

  2. Geoff Cox

    Greg Bacon Guest

    In article <>,
    Geoff Cox <> 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
     
    Greg Bacon, Oct 12, 2003
    #2
    1. Advertising

  3. Geoff Cox

    Geoff Cox Guest

    On Sun, 12 Oct 2003 11:29:40 -0000, (Greg Bacon)
    wrote:

    >In article <>,
    > Geoff Cox <> 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
     
    Geoff Cox, Oct 12, 2003
    #3
  4. Geoff Cox

    Lao Coon Guest

    Geoff Cox <> wrote in
    news::

    > 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
     
    Lao Coon, Oct 12, 2003
    #4
  5. Geoff Cox

    Geoff Cox Guest

    On Sun, 12 Oct 2003 13:55:20 +0200, Lao Coon <>
    wrote:

    >Geoff Cox <> wrote in
    >news::
    >
    >> 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
     
    Geoff Cox, Oct 12, 2003
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Hunsley
    Replies:
    1
    Views:
    602
    Andrew Thompson
    Sep 16, 2004
  2. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    907
    Mark Rae
    Dec 21, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,984
    Smokey Grindel
    Dec 2, 2006
  4. MoshiachNow
    Replies:
    2
    Views:
    275
    Ilya Zakharevich
    Oct 4, 2006
  5. Bo Yang
    Replies:
    9
    Views:
    305
    -berlin.de
    Nov 20, 2006
Loading...

Share This Page