kcott has asked for the wisdom of the Perl Monks concerning the following question:
Given a directory structure which looks something like this (which I've been using for testing):
fred fred/asd fred/derf fred/qwe fred/zxc fred/derf/fgh fred/derf/rty fred/derf/fgh/vbn
I'm looking for a way to implement the following command in Perl:
$ tar zcvf fred.tar.gz fred
I thought the builtin Archive::Tar module was possibly the way to go. I can get this to achieve what I want but it's horribly clunky:
use Archive::Tar; my $tar = Archive::Tar::->new(); $tar->add_files(glob "fred fred/* fred/*/* fred/*/*/*"); $tar->write("fred.tar.gz", COMPRESS_GZIP);
This has additional problems in that the directory structure could be deeper and hidden files (starting with '.') are not captured by any of those glob patterns.
I tried using "fred" and "fred/" as the sole arguments to add_files() but they only pick up the top-level directory, not the rest of the directory structure. I can't see an add_directory() (or similarly named) method. I also tried with the create_archive() class method but had a similar lack of success.
I've also had a hunt around various core and CPAN modules in the Archive:: and IO:: namespaces: none seemed to do what I want.
I could write a recursive routine to capture the entire directory into an array (for add_files(@filenamelist)). That would be my fallback plan but I was hoping there might be a more elegant (less code) way of doing this.
Any ideas on how I might achieve what I want with either Archive::Tar, or some other module, would be appreciated.
— Ken
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Creating a tarball
by tybalt89 (Monsignor) on Feb 07, 2019 at 06:57 UTC | |
by Tux (Canon) on Feb 07, 2019 at 07:30 UTC | |
by tybalt89 (Monsignor) on Feb 07, 2019 at 07:41 UTC | |
by kcott (Archbishop) on Feb 07, 2019 at 12:39 UTC | |
by kcott (Archbishop) on Feb 07, 2019 at 12:08 UTC | |
by Aldebaran (Curate) on Feb 10, 2019 at 08:35 UTC | |
|
Re: Creating a tarball
by haj (Vicar) on Feb 07, 2019 at 06:44 UTC | |
by kcott (Archbishop) on Feb 07, 2019 at 11:38 UTC | |
by haj (Vicar) on Feb 07, 2019 at 12:41 UTC | |
|
Re: Creating a tarball [SOLUTION]
by kcott (Archbishop) on Feb 07, 2019 at 23:27 UTC |