分类: LINUX
2010-09-02 08:47:11
#!/usr/bin/perl use strict; use warnings; use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); use Encode qw/from_to/; use Getopt::Long; use DateTime; use DateTime::TimeZone::Local; GetOptions('list|l' => \ my $mode_list); if (scalar @ARGV < 1) { print "Usage: $0 [-l]\n"; exit 1; } my $zipfile = shift @ARGV; my $zip = Archive::Zip->new(); unless ( $zip->read($zipfile) == AZ_OK ) { die 'read error'; } print "Archive: $zipfile\n"; if ($mode_list) { print < Length Date Time Name -------- ---------- ----- ---- HERE } my $total_size = 0; my @members = $zip->members(); my $members_count = scalar @members; foreach my $member (@members) { my $filename = $member->fileName; from_to($filename, 'cp932', 'utf8'); if ($mode_list) { my $dt = DateTime->from_epoch( epoch => $member->lastModTime )->set_time_zone(DateTime::TimeZone::Local->TimeZone()); $total_size += $member->uncompressedSize; printf "%9d %s %s\n", $member->uncompressedSize, $dt->ymd('-') . ' ' . sprintf("%02d", $dt->hour) . ':' . sprintf("%02d", $dt->min), $filename; } else { print " inflating: $filename\n"; unless (defined $zip->extractMember($member, $filename)) { warn " failed: $filename\n"; } } } my $members_count_str = "$members_count file" . ($members_count > 1 ? 's' : ''); if ($mode_list) { print < -------- ------- HERE printf "%9d %s\n", $total_size, $members_count_str; }
chinaunix网友2010-09-04 14:36:06
Download More than 1000 free IT eBooks: http://free-ebooks.appspot.com