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