in reply to Re^2: 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 was able to get rid of the MKV zip file. Forgot a couple of lines that stevieb had suggested.

New code is:

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 "$dir/*.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"; }

Still trying to figure out how to remove the partial directory structure within the apxxxx.zip files

  • Comment on Re^3: Create zip files for each sub-directory under a main directory
  • Download Code

Replies are listed 'Best First'.
Re^4: Create zip files for each sub-directory under a main directory
by mrd1019 (Novice) on Nov 30, 2016 at 18:17 UTC

    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"; }