使用进度指示器在cmd上解压缩zip文件

时间:2011-01-13 07:38:11

标签: perl command-line progress-bar unzip

我正在寻找一个程序,它能够通过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;
}

但是我有两个问题:

  • 这种方法似乎很慢
  • 我没有在进度条中定期更新,但仅在文件完成时才提取。由于我有一些大文件,系统似乎在提取它们时没有响应

1 个答案:

答案 0 :(得分:1)

从程序中进行提取,而不是委托给另一个程序。使用Archive::ZipTerm::ProgressBar。逐个提取文件。在每次之后更新进度。