palkia has asked for the wisdom of the Perl Monks concerning the following question:

Hello.

I need to rename "members" (files within zip files), that have problematic characters for my OS (win xp).
I have constructed a simple (and long) regex rule to filter out such problematic chars, but then noticed that although the zip module cpan doc says it can be used to rename "members", it doesn't actually show how (as far as I can understand anyway).
I would like if possible to avoid a full overwrite of the entire zip file with its own reconstructed version, as I would probably have to run this over a large number of zip files in the near future.

Your thoughts ?
Thx

Replies are listed 'Best First'.
Re: Renaming a file within a zip
by haukex (Archbishop) on Oct 03, 2017 at 08:44 UTC
    doc says it can be used to rename "members", it doesn't actually show how

    It's a little hard to find, see the section "Member Operations":

    fileName() / Get or set the member's internal filename.

    This works for me:

    use Archive::Zip qw/:ERROR_CODES :CONSTANTS/; my $zip = Archive::Zip->new(); $zip->read('/tmp/foo.zip')==AZ_OK or die "read"; for my $member ($zip->members) { next if $member->isDirectory; my $fn = $member->fileName; $fn =~ s/foo/bar/; $member->fileName($fn); } $zip->overwrite==AZ_OK or die "write";

    Update: My 1111th node! :-)

      Works for me too.
      Thank you very much for helping me figure this out and for the relevant and generally useful link. ☺
Re: Renaming a file within a zip
by Anonymous Monk on Oct 03, 2017 at 06:39 UTC
    I wrote example how to get unicode filenames from zips. The distribution comes with example of renaming and i also wrote example.
      Umm.. Thx ?
      So.. you (Anonymous) have, in some point in the past, wrote some example that you believe can solve this problem.
      But you won't say what it is, nor how I can find it ?
      ... Well.. as emotionally supportive as it is, to know the solution is within the realm of possibility, and more so to know it was actually previously achieved by someone.. I don't really see how you expect me to practically use this information to get closer to the solution..
      Well, whatever was on your mind when you posted this, thx for trying.

        Umm.. Thx ? So.. you (Anonymous) have, in some point in the past, wrote some example that you believe can solve this problem. But you won't say what it is, nor how I can find it ? ... Well.. as emotionally supportive as it is, to know the solution is within the realm of possibility, and more so to know it was actually previously achieved by someone.. I don't really see how you expect me to practically use this information to get closer to the solution.. Well, whatever was on your mind when you posted this, thx for trying.

        Cool, you actually read my post and responded this time, thats like new for you. Maybe if you search for "unicode zip" you'll find something you like.