[英]How to gzip several files in Perl one by one
我有要使用Perl壓縮的文件列表。 目前我有這個:
gzip \@tocompress -> $outputfile
or die "Failed to compress: $GzipError\n"
但是我想遍歷文件,然后一次將它們添加到壓縮文件中。 我該如何實現?
看來您正在使用IO :: Compress :: Gzip 。 使用gzip
的Append
選項:
#!/usr/bin/perl
use warnings;
use strict;
use IO::Compress::Gzip qw{ gzip $GzipError };
my $outputfile = 'out.gz';
my @tocompress = glob '*.txt';
for my $file (@tocompress) {
next unless -f $file;
print STDERR "Adding $file\n";
gzip($file, $outputfile, Append => 1) or die $GzipError;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.