perl 遍历文件夹, 压缩文件

use Archive::Zip qw( :ERROR_CODES :CONSTANTS );

my $aaa = "D:\\NCR_v2.2.2\\test";
my $zip = Archive::Zip->new();
#foreach $file (@files) {
#   $zip->addFile("$aaa/$file", $bbb);
#}

# Add a directory
my $dir_member = $zip->addDirectory( 'dirname/' );
  
# Add a file from a string with compression
my $string_member = $zip->addString( 'This is a test', 'stringMember.txt' );
$string_member->desiredCompressionMethod( COMPRESSION_DEFLATED );
  
# Add a file from disk
my $file_member = $zip->addFile( '1.txt' );
  
# Save the Zip file
unless ( $zip->writeToFileNamed('someZip.zip') == AZ_OK ) {
     die 'write error';
}

my $path = "D:\\v4.3\\";
opendir(DIR, $path);
foreach $file(readdir DIR) {
if ($file ne "." && $file ne "..") {
print("$file\n");
}
}
closedir(DIR);

你可能感兴趣的:(遍历文件夹)