Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Getting IO::Compress::Zip to include directory entries (on Windows)

by hilitai (Monk)
on Feb 03, 2016 at 00:35 UTC ( [id://1154310]=note: print w/replies, xml ) Need Help??


in reply to Re: Getting IO::Compress::Zip to include directory entries (on Windows)
in thread Getting IO::Compress::Zip to include directory entries (on Windows)

Thanks! But I guess I wasn't clear enough. I can already include all the files, in whatever directory; what I'm trying to do is include the directory entry itself, like a native zip program would do.

For example, here's the output of Zip 3.0:

C:\Temp\ztest>zip -r test2.zip WEB-INF adding: WEB-INF/ (208 bytes security) (stored 0%) <-- dir, not file adding: WEB-INF/deploy/ (208 bytes security) (stored 0%) <-- ditto adding: WEB-INF/deploy/client/ (208 bytes security) (stored 0%) adding: WEB-INF/deploy/client/rpcPolicy/ (208 bytes security) (store +d 0%) adding: WEB-INF/deploy/client/rpcPolicy/manifest.txt (208 bytes secu +rity) (deflated 4%) <-- first actual file

So it's stored the directory entities and information (including modification times) as well as the files. That's what I'm trying to emulate.

I've done some more digging around, and I'm beginning to think that IO::Compress::Zip might just not do what I want. Also, I didn't think that Archive::Zip was in the core libraries, but it looks like it has been since v 5.12 or so, maybe. (On the other hand, I have to work with some very old systems.)

I might not even need this ability for what I want to do, but the closer I can come to a Real Zip File on output, the better.

  • Comment on Re^2: Getting IO::Compress::Zip to include directory entries (on Windows)
  • Download Code

Replies are listed 'Best First'.
Re^3: Getting IO::Compress::Zip to include directory entries (on Windows)
by poj (Abbot) on Feb 03, 2016 at 07:48 UTC
    what I'm trying to do is include the directory entry itself

    In the docs it says filenames only

    If $input is an array reference, each element in the array must be a filename. The input data will be read from each file in turn. The complete array will be walked to ensure that it only contains valid filenames before any data is compressed.
    poj

      IO::Compress::Zip cannot write directories (without jumping through a lot of hoops) by design.

      I do have another module, called Archive::Zip::SimpleZip (it actually uses IO::Compress::Zip under the hood), that can create directories.

      Here is a example of how to use it

      use strict ; use warnings; use Archive::Zip::SimpleZip; my @dirs = ("WEB-INF"); my $zip = Archive::Zip::SimpleZip->new("test.zip"); $zip->add($_) for @dirs; $zip->close();

      and here is what the commandline unzip this about the zip file

      $ unzip -l test.zip Archive: test.zip Length Date Time Name --------- ---------- ----- ---- 0 02-03-2016 12:58 WEB-INF/ --------- ------- 0 1 file
Re^3: Getting IO::Compress::Zip to include directory entries (on Windows)
by dasgar (Priest) on Feb 03, 2016 at 05:41 UTC
    But I guess I wasn't clear enough.

    Actually, I think that I understood you correctly, but I probably failed to properly describe what I tested.

    Here's the file and directory layout of what I tested (and the contents of test.pl is the code from my previous post):

    C:\test\test.pl C:\test\test_dir\file1.txt C:\test\test_dir\file2.txt

    After running perl test.pl, I got a new file: C:\test\test.zip. Here's the contents of test.zip:

    test_dir\file1.txt test_dir\file2.txt

    As you can see, the file and directory structure was fully and correctly added into the new zip file. And a quick check shows that the two text files' modification date/time stamp is preserved in the new zip file too. I believe that is the basic idea of what you are trying to do. However, I suspect that you'll need to make modifications to the code that I posted in order to fully do what you're trying to do.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1154310]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2024-04-23 12:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found