in reply to Re: Create zip files for each sub-directory under a main directory
in thread Create zip files for each sub-directory under a main directory
Thanks for all the help guys! I'm new to perl, been trying to teach myself via websites like this and books. Nothing compares to having experienced users help out though!
I've updated the code, based on a lot of the advice I've been given. The code now creates the zip files correctly (correct name with all the files inside). There are still a couple of things I'd like to change though. First, it creates a zip file of the top level directory (mkv in the $mkvingestdir). I don’t need that zip file. Additionally, the apxxxx.zip files don’t contain just the files, but also contain the directory path (i.e., inside the zip it is not just the .eap files, but mine/MKV/apxxxx/files).
How would I go about eliminating the MKV zip file that is created, and limit the zip’s to only have the files, and not the directory structure?
As for the single vs. double quotes that Anonymous mentioned…..as I said, I’ve been learning via websites for the most part, and I see all these different examples. I feel like I’m starting to understand the basics of perl, but there is always so much to learn. I know this code is not perfect, but I’m continually reading/studying to try and make it, and myself better. I really want to thank everyone for all the help with this.
Having said all that, here is my code as it stands now
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; 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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Create zip files for each sub-directory under a main directory
by Anonymous Monk on Dec 02, 2016 at 08:13 UTC | |
|
Re^3: Create zip files for each sub-directory under a main directory
by mrd1019 (Novice) on Nov 30, 2016 at 17:58 UTC | |
by mrd1019 (Novice) on Nov 30, 2016 at 18:17 UTC |