#! perl -w
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
my $zip = Archive::Zip->new(); ###创建压缩文件,如果有参数则按读取该文件的内容
1.压缩ZIP
$zip->addTree("F:/kx_code","123");
unless ( $zip->writeToFileNamed('kx_code.zip') == AZ_OK ) {
die 'write error';
} ##成功返回OK
2.解压ZIP
use Archive::Extract;
my $ar = Archive::Extract->new( archive => "F:/kc_code.zip"); ###欲解压的ZIP包名
my $ok = $ar->extract( to => "E:/123") or die; ###解压到的目录
3.查看压缩文件
my $status = $zip->read( 'kx_code.zip' );
foreach my $file($zip->members())
{
print $file->fileName(), ", ", $file->uncompressedSize(), ":", $file->compressedSize(), "n";
}
##返回压缩文件名 压缩前文件大小 压缩后文件大小
4.已有的ZIP文件中添加新的文件
$obj->addFile("otherstuff/header.gif");
$obj->overwrite(); ###成功返回AZ_OK
阅读(3743) | 评论(0) | 转发(0) |