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.

#!/bin/bash
# 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
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    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 <http://www.gnu.org/licenses/>.
#Deepak Barua is a member of the
# Linconsulo Group
# contact@linconsulo.com
# www.linconsulo.com
export WORKFILE=realfile
export REALFILE=testfile2
export ZIPFILE=test.zip
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";
'
Advertisements

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:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: