|
发表于 2010-10-7 20:31:00
|
显示全部楼层
参考arch官方论坛某贴和这个帖子,再从不知某处扒了个unzip的perl实现,自己做了一个perl脚本
用perl的Archive::Zip模块是为了处理中文zip不产生乱码
- #!/usr/bin/perl -w
- #########################################################################
- # Author: stesen
- # Created Time: Thu 07 Oct 2010 05:31:52 PM CST
- # File Name: e.pl
- # Description: try to decompress files
- #########################################################################
- #use strict;
- use Archive::Zip;
- use Encode qw(decode encode);
- my ($archive, $basenme, $bh, $fh);
- foreach $archive (@ARGV) {
- $archive =~ m/\b([^\.]*)\..*\b/;
- $fh = $1;
- $fh =~ s/\s//g;
- if (-e $archive) {
- if ($archive =~ m/(\.tar\.bz2)|(\.tar\.gz)|(\.tar)|(\.tgz)|(\.tbz2)\b/) {
- system "time", "-p", "tar", "xvf", $archive;
- } elsif ($archive =~ /\.bz2\b/) {
- system "time", "-p", "bunzip2", $archive;
- } elsif ($archive =~ m/\.rar\b/i) {
- system "mkdir", "-v", $fh;
- system "time", "-p", "unrar", "x", $archive, $fh;
- } elsif ($archive =~ /\.gz\b/) {
- system "time", "-p", "gunzip", $archive;
- } elsif ($archive =~ m/(\.zip)|(\.jar)\b/i) {
- system "mkdir", "-v", $fh;
- chdir("$fh") or die "$!";
- &uzip("../$archive");
- chdir("..");
- } elsif ($archive =~ /\.Z\b/) {
- system "time", "-p", "uncompress", $archive;
- } elsif ($archive =~ /\.7z\b/) {
- system "time", "-p", "7z", "x", $archive;
- } elsif ($archive =~ /.xz\b/) {
- system "time", "-p", "xz", "-d", $archive;
- } else {
- print("don\'t know how to extract" . $archive . "..."."\n");
- }
- } else {
- print("$archive is not a valid file!" . "\n");
- }
- }
- sub uzip {
- my ($zip, $from, $to);
- $zip = Archive::Zip->new($_[0]);
- $from = $_[1] || 'utf-8';
- $to = $_[2] || 'utf-8';
- for ($zip->memberNames()) {
- $member = $zip->memberNamed($_);
- $_ = encode($to, decode($from, $_));
- $zip->extractMember($member, $_);
- }
- }
复制代码 |
|