unzip.pl input.tar.gz
input.tar.gz 文件里还有a.tar.gz;b.tar.gz文件; a.tar.gz文件里还有.tar, .jar文件。
这个程序的目的就是要把input.tar.gz文件里的所有可以解压的tar/jar/tar. ... [/quote]
use warnings;
############# Main Begin ################
if ($ARGV[0]) {
&deep_unzip($ARGV[0]);
}
else {
print "Usage: DeepUnzip.pl 'file1' 'file2' 'filen'\n";
}
############# Main End ##################
### unzip the target recursively
sub deep_unzip {
my $target = shift;
if ($target =~ /\.jar$/i) {
print "jar -xf $target\n";
system("jar -xf $target");
$target =~ s/\.jar$//i;
}
elsif ($target =~ /\.tar$/i) {
print "tar -xf $target\n";
system("tar -xf $target");
$target =~ s/\.tar$//i;
}
elsif ($target =~ /\.tar\.gz$/i) {
print "gunzip -f $target\n";
system("gunzip -f $target");
$target =~ s/\.gz$//i;
print "tar -xf $target\n";
system("tar -xf $target");
$target =~ s/\.tar$//i;
}
# unzip the new files recursively
if (-d $target) {
print "cd $target\n";
chdir($target);
my @new_files = glob "*";
foreach (@new_files) {
&deep_unzip($_);
}
print "cd ..\n";
chdir('..');
}
}
阅读(929) | 评论(0) | 转发(0) |