add zip_nes_roms.pl, batch recursive zip pack script
This commit is contained in:
56
zip_nes_roms.pl
Executable file
56
zip_nes_roms.pl
Executable file
@@ -0,0 +1,56 @@
|
|||||||
|
#!/usr/bin/perl
|
||||||
|
#
|
||||||
|
# this script conpress all *.nes files in current dir' subdirs with zip
|
||||||
|
#
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings "all";
|
||||||
|
use IO::Compress::Zip qw(:all);
|
||||||
|
|
||||||
|
sub zlist(@);
|
||||||
|
my $L1;
|
||||||
|
opendir($L1, ".") || die;
|
||||||
|
my @L1DIR = readdir($L1);
|
||||||
|
closedir($L1);
|
||||||
|
undef $L1;
|
||||||
|
|
||||||
|
foreach my $l1dir (@L1DIR) {
|
||||||
|
next if($l1dir eq ".");
|
||||||
|
next if($l1dir eq "..");
|
||||||
|
|
||||||
|
if (-d $l1dir) {
|
||||||
|
chdir ($l1dir);
|
||||||
|
my @list;
|
||||||
|
opendir DIR, "." || die;
|
||||||
|
|
||||||
|
while (readdir(DIR)){
|
||||||
|
if ((-f $_) and (($_ =~ /nes$/) or ($_ =~ /unf$/))){ push @list, $_; }
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir (DIR);
|
||||||
|
zlist(@list);
|
||||||
|
@list = -1; undef @list;
|
||||||
|
chdir("..");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
exit 0;
|
||||||
|
|
||||||
|
sub zlist(@){
|
||||||
|
my @list = @_;
|
||||||
|
my $item;
|
||||||
|
|
||||||
|
foreach $item (@list) {
|
||||||
|
printf ("zipping: %s to %s.zip", $item, $item);
|
||||||
|
zip [$item] => "$item.zip", -Level => Z_BEST_COMPRESSION, Minimal => 1, TextFlag => 1;
|
||||||
|
|
||||||
|
if(length($ZipError) > 0){
|
||||||
|
printf ("Warning: unable to zip %s - %s\n", $item, $ZipError);
|
||||||
|
}else{
|
||||||
|
printf (" and deleting source file\n");
|
||||||
|
unlink($item);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user