我正在寻找一个程序,它能够通过Windows命令行提取zip档案,并且能够在cmd上显示进度条或百分比指示器。我想在Perl脚本中使用它,因此给用户提示进度需要多长时间。到目前为止,我尝试过7zip(http://www.7-zip.org/)和Unzip(from InfoZIP),但是无法产生上述行为。有人知道如何解决这个问题吗?
更新: 目前我正在尝试这种方法:
#!/usr/bin/perl
use strict; $|++;
use warnings;
use Archive::Zip;
my $zip = Archive::Zip->new('file.zip');
my $total_bytes = 0;
my $bytes_already_unzipped = 0;
foreach my $member ($zip->members()) {
$total_bytes += $member->uncompressedSize();
}
foreach my $member ($zip->members()) {
$zip->extractMember($member);
$bytes_already_unzipped += $member->uncompressedSize();
print progress_bar($bytes_already_unzipped, $total_bytes, 25, '=' );
}
#routine by tachyon at http://tachyon.perlmonk.org/
#also have a look at http://oreilly.com/pub/h/943
sub progress_bar {
my ( $got, $total, $width, $char ) = @_;
$width ||= 25; $char ||= '=';
my $num_width = length $total;
sprintf "|%-${width}s| Got %${num_width}s bytes of %s (%.2f%%)\r",
$char x (($width-1)*$got/$total). '>',
$got, $total, 100*$got/+$total;
}
但是我有两个问题: