in reply to Re^2: unable to extract same file twice using Archive::Zip
in thread unable to extract same file twice using Archive::Zip

Using your example it would make more sense to simply copy foo.txt as bar.txt instead of extracting it twice...


So the issues/requirements you are facing at this point are:
Forgive me, but I don't understand. I would gladly offer whatever help I can provide, but this problem your facing doesn't make sense... please clarify

PS.
It's really a lot easier, and the files need to be extracted twice are really small, to extract some members twice, rather than storing which member already has been extracted and reuse those files and cleaning up later etc. .
For what its worth, how about this approach:
1. Obtain your "special" ordering of your zip file members.  my @member_order = $zip->members();
2. Extract the entire archive to a directory. $zip->extractTree( 'stuff', '/tmp' );
3. Process/reprocess the files in the extracted temp directory as required, based on their order within @member_order

If this approach is unsuitable, why not?

Replies are listed 'Best First'.
Re^4: unable to extract same file twice using Archive::Zip
by Pickwick (Beadle) on Jul 06, 2010 at 12:41 UTC
    I must extract the file from the archive twice as i cannot copy the extracted version to the second location

    Of course I can. Ihe problem is that I don't wanted to always remember what already has been extracted, let it stay on the disk, reuse it, if even necessary, and cleanup later. Extracting it a second time if I already know that it's needed and don't have to look if it's already extracted would have been less code.

    Forgive me, but I don't understand. I would gladly offer whatever help I can provide, but this problem your facing doesn't make sense... please clarify

    The main question is: Is there a limitation on how often one can extract the same zip member and if, why? I don't see any reason why one shouldn't be able to extract a member more than once, if he wants to.

    If this approach is unsuitable, why not?

    In my mind it's waste of space to extract everything at once if I always just need one or two files from the archive. If there are two same named files in the archive you get a problem, too.

    But as I said before, I really would like to know if it's possible to extract a member more than once or not. Maybe I'm just missing something like endRead in the proper way or stuff like that.

      I don't think you tested your example somehow, theres a typo in your method call extractToFileNames() should actually be extractToFileNamed().

      Having modifed that, your example works perfectly fine for me on winXP, perl 5.8.8, zip.pm v1.20 - perhaps you've found some sort of regression bug. What versions are you using? And what actually happens when you attempt to extract a member twice? (Maybe paste the console output into a <code></code> block)

      BTW, since your example didn't include it, are your using use strict; use warnings;

        Having modifed that, your example works perfectly fine for me on winXP, perl 5.8.8, zip.pm v1.20

        That's what I wanted to read, thanks. Seems it should work, but it doesn't for me. I have version 1.30 on Perl 5.10.1.1007 on Win Server 2003 R2 SP2.