Perl 使用进度指示器在cmd上提取zip文件
我正在寻找一个程序,它能够通过windows命令行提取zip档案,并且能够在cmd上显示progressbar或百分比指示器。我想在Perl脚本中使用它,并向用户提示进度需要多长时间。我试了7zip(http://www.7-zip.org/)到目前为止,但未能产生上述行为。有人知道怎么解决这个问题吗 更新: 目前我正在尝试这种方法:Perl 使用进度指示器在cmd上提取zip文件,perl,command-line,progress-bar,unzip,Perl,Command Line,Progress Bar,Unzip,我正在寻找一个程序,它能够通过windows命令行提取zip档案,并且能够在cmd上显示progressbar或百分比指示器。我想在Perl脚本中使用它,并向用户提示进度需要多长时间。我试了7zip(http://www.7-zip.org/)到目前为止,但未能产生上述行为。有人知道怎么解决这个问题吗 更新: 目前我正在尝试这种方法: #!/usr/bin/perl use strict; $|++; use warnings; use Archive::Zip; my $zip = Ar
#!/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;
}
然而,我有两个问题:
- 这种方法似乎非常缓慢
- 我在进度条中没有定期更新,但只有在完成文件提取后才进行更新。由于我有一些大文件,系统在提取它们时似乎没有响应