繁体   English   中英

如何使用perl脚本从多个子文件夹中解压缩1个以上文件?

[英]How to unzip more than 1 files from more than one sub-folders using perl script?

我在父目录中有多个子文件夹,每个子文件夹都有10多个zip文件。 父目录:/ parentdir子目录:/ parentdir / 2011-01,2011-02 ...直到2014-06,依此类推..每个月。

每个子目录:file1.zip,file2.zip,... file10.zip

我想使用perl脚本解压缩同一子文件夹中的所有文件,并在解压缩后删除.zip文件,或者仅将file1.zip解压缩到file1

您能否在UNIX计算机上使用PERL脚本来帮助实现这一目标?

有可能使用

use strict;
use warnings;
use IO::Uncompress::Unzip qw(unzip $UnzipError);

my $zipfile = $ARGV[0];
my $u = new IO::Uncompress::Unzip $zipfile
or die "Cannot open $zipfile: $UnzipError";

die "Zipfile has no members"
 if ! defined $u->getHeaderInfo;
}

但是它提供了仅解压缩/解压缩一个文件的选项

更新米勒的答案

使用了http://pkgs.org/centos-6/epel-i386/perl-Path-Class-0.25-1.el6.noarch.rpm.html并为要进行侦察的Path :: Class安装了rpm。现在仍然无法解压缩子文件夹中的文件:IO :: Uncompress :: Unzip:unzipper.pl第13行的输入参数不是文件名,文件句柄,数组引用或标量引用

我在子文件夹中有一个父文件夹api_parent_folder-2014-01、2014-02 ...

在上面的脚本中,我已将/ parentdir更改为/ mnt / api_parent_folder

我走的永远如下

现在仍然无法解压缩子文件夹中的文件:IO :: Uncompress :: Unzip:unzipper.pl第13行的输入参数不是文件名,文件句柄,数组引用或标量引用

使用Path::Class遍历目录结构:

use strict;
use warnings;

use Path::Class;
use IO::Uncompress::Unzip qw(unzip $UnzipError);

my $dir = dir('/parentdir');

while ( my $subdir = $dir->next ) {
    next unless $subdir->is_dir();
    while ( my $zipfile = $subdir->next ) {
        my $u = IO::Uncompress::Unzip->new("$zipfile")
            or die "Cannot open $zipfile: $UnzipError";

        die "Zipfile has no members" if !defined $u->getHeaderInfo;
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM