Technical Discussions

Thoughts on Engineering & Technology

Solution to rename file in a zip archive

Hi Guys,

AT developed this solution for a guy in the perl_help mailing list , he wanted a solution in perl to rename files in a zip archive.

Here is his code snippet.

# Zip filename converter script
#    Copyright (C) 2008  Deepak Barua
#   This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.

#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    GNU General Public License for more details.

#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <>.
#Deepak Barua is a member of the
# Linconsulo Group
export WORKFILE=realfile
export REALFILE=testfile2
perl -e '
use strict;
use warnings;
use Archive::Zip qw( :ERROR_CODES );
my $zip = Archive::Zip->new();
$zip->read($ENV{ZIPFILE}) == AZ_OK or die "read error \n";
my $m1 = $zip->memberNamed($ENV{WORKFILE});
$m1->fileName($ENV{REALFILE});                # Renamed file
$zip->overwrite()  == AZ_OK or die " Write error \n";

October 8, 2008 - Posted by | perl, Software | , , ,

No comments yet.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: