[英]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.