in reply to Re^3: Create zip files for each sub-directory under a main directory
in thread Create zip files for each sub-directory under a main directory
I GOT IT!!!!! (Sorry, very happy right now). Once I added in the next if statements, and had set to chdir, I made one last change, and the code now works as I want it to!
Once again, a HUGE thank you to everyone that assisted!! Looking forward to continuing my journey here with perl.
Newest code, in case anyone is wondering:
use strict; use warnings ‘all’; use File::Copy::Recursive; use Archive::Zip; use constant AZ_OK =>0; use File::Basename; use File::Find::Rule; my $mkvingestdir = “//nas/shared/mine/MKV” my $mkvingestdest = “//nas/shared/group/test/mkv/ingest”; my @dirs = File::Find::Rule->directory() ->in($mkvingestdir); foreach my $dir (@dirs) { chdir $dir; next if $dir =~ /(?:\.|\.\.)/; next if $dir eq $mkvingestdir; print “Now processing directory $dir\n”; my @files = glob "*.eap"; my $mkvingestzip = Archive::Zip->new(); foreach $file (@files) { $mkvingestzip->addFile($file); } my $name = basename $dir; if ($mkvingestzip->writeToFileNamed("$mkvingestdest/${name}.zip") + != AZ_OK) { print "Error in archive creation\n"; next; } print "Archive created successfully!\n"; }
|
|---|