1 2 3 4 5 6 7 8 9 10
use Archive::Zip qw(:ERROR_CODES :CONSTANTS); my @verzeichnisse = ('/root/homepage1/verz2','/root/homepage1/verz4'); my $zip = Archive::Zip->new(); while (scalar @verzeichnisse) { my $verz = shift @verzeichnisse; $zip->addTree($verz,$verz,undef,COMPRESSION_LEVEL_BEST_COMPRESSION); if ($zip->writeToFileNamed('/zielpfad/datei.zip') != AZ_OK) { die "Kann ZIP '/zielpfad/datei.zip' nicht schreiben"; } }
QuoteNote that you generally don't want to make zip archive member names absolute.
2016-01-12T10:32:45 biancaIn der Doku lese ich dies hier, weiß aber nicht, worauf sich das bezieht:
QuoteNote that you generally don't want to make zip archive member names absolute.
2016-01-12T11:02:39 RaubtierSpricht etwas dagegen, einfach einen Leerstring zu übergeben?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
D:.
└───homepage1
├───verz1
│ │ abc.txt
│ │ def.txt
│ │
│ └───unterverz11
├───verz2
│ │ ghi.txt
│ │ jkl.txt
│ │
│ └───unterverz21
├───verz3
│ │ mno.txt
│ │ pqr.txt
│ │
│ └───unterverz31
├───verz4
│ │ stu.txt
│ │ vwx.txt
│ │
│ └───unterverz41
└───zipziel
zip.zip
1 2 3 4
my $verz = shift @verzeichnisse; my $ohneShash = $verz; $ohneSlash =~ s#^/##; $zip->addTree($verz,$ohneSlash,undef,COMPRESSION_LEVEL_BEST_COMPRESSION);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#!/usr/bin/perl use strict; use warnings; use Archive::Zip qw(:ERROR_CODES :CONSTANTS); if ($^O =~ /mswin/i) { $Archive::Zip::UNICODE = 1; } my @verzeichnisse = ('/webserver/homepage1/verz2','/webserver/homepage1/verz4'); my $zip = Archive::Zip->new(); while (scalar @verzeichnisse) { my $verz = shift @verzeichnisse; $zip->addTree($verz,substr($verz,1),undef,COMPRESSION_LEVEL_BEST_COMPRESSION); if ($zip->writeToFileNamed("/webserver/homepage1/zipziel/zip.zip") != AZ_OK) { die "Kann ZIP '/webserver/homepage1/zipziel' nicht schreiben"; } }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
└───homepage1
├───verz1
│ │ abc.txt
│ │ def.txt
│ │
│ └───unterverz11
├───verz2
│ │ ghi.txt
│ │ jkl.txt
│ │
│ └───unterverz21
├───verz3
│ │ mno.txt
│ │ pqr.txt
│ │
│ └───unterverz31
├───verz4
│ │ stu.txt
│ │ vwx.txt
│ │
│ └───unterverz41
└───zipziel
zip.zip
perldoc Archive::Zip...
$Archive::Zip::UNICODE
This variable governs how unicode file and directory names are added to or extracted from an archive. If set, file and directory names are considered to be UTF-8 encoded. This is EXPERIMENTAL AND BUGGY (there are some edge cases on Win32). Please report problems.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
#!/usr/bin/perl use strict; use warnings; use 5.010; use Archive::Zip qw(:ERROR_CODES :CONSTANTS); if ($^O =~ /mswin/i) { $Archive::Zip::UNICODE = 1; } my $add_verzeichnisse = 0; # 0=selbst iterieren 1=->addTree() verwenden my @verzeichnisse = ('/webserver/homepage1/verz2','/webserver/homepage1/verz4'); my $zip = Archive::Zip->new(); while (scalar @verzeichnisse) { my $verz = shift @verzeichnisse; if ($add_verzeichnisse) { $zip->addTree($verz,substr($verz,1),undef,COMPRESSION_LEVEL_BEST_COMPRESSION); } else { if (opendir(my $fh,$verz)) { foreach my $file (readdir $fh) { next if $file eq '.' || $file eq '..'; if (-d "$verz/$file") { push @verzeichnisse,"$verz/$file"; say "neues Verzeichnis '$verz/$file'"; } else { if (open(my $t,'<',"$verz/$file")) { close($t); my $file_member = $zip->addFile({ filename => "$verz/$file", compressionLevel => COMPRESSION_LEVEL_BEST_COMPRESSION, }); say "adde '$verz/$file'"; } else { say "$verz/$file nicht lesbar" } } } } } } if ($zip->writeToFileNamed("/webserver/homepage1/zipziel/zip.zip") != AZ_OK) { die "Kann ZIP '/webserver/homepage1/zipziel' nicht schreiben"; }