Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

using Archive::Tar

by ansh batra (Friar)
on Oct 04, 2011 at 09:38 UTC ( [id://929483]=perlquestion: print w/replies, xml ) Need Help??

ansh batra has asked for the wisdom of the Perl Monks concerning the following question:

hi monks i am facing problem in using Archive::Tar
Archive::Tar->create_archive('Bundle-FinalTest.tar.gz', COMPRESS_GZIP, +'Bundle::Finaltest);
this only compress the folder Bundle::FinalTest but i want that it should contain all the subfolders and files of Bundle::FinalTest. please help!

Replies are listed 'Best First'.
Re: using Archive::Tar
by keszler (Priest) on Oct 04, 2011 at 11:06 UTC

    The third argument to create_archive is defined as @filelist, with the explanation:

    The remaining arguments list the files to be included in the tar file. These files must all exist. Any files which don't exist or can't be read are silently ignored.

    Note that no mention is made of directories, just files. create_archive does not recurse through directories; you must specify each file to be archived.

Re: using Archive::Tar
by pvaldes (Chaplain) on Oct 04, 2011 at 13:40 UTC
    use strict; use warnings; use autodie; use Archive::Tar; my @filelist = (); opendir(my $dir, '/path/to/my/dir/'); while(readdir $dir) { chomp; if (!~ /(^\.\.|\.)$/){ push @filelist, $_; } } my $pack = Archive::Tar->new; $pack->create_archive('Bundle-FinalTest.tgz', COMPRESS_GZIP, @filelist +); closedir $dir;

    UPDATE: A couple of changes, but Not properly working still...

    a lot of "not such file: filename" error messages, I don't know why

    Alternatively, you can use the old cheap way, that is guaranteed to act as you expect:

    `tar -zcvvf Bundle-FinalTest.tgz /path/to/Bundle/FinalTest/dir/`;

      Combine with File::Find:

      use strict; use warnings; use autodie; use Archive::Tar; use File::Find; my @fl; find (sub { -d $_ or push @fl, $File::Find::name }, "Bundle::Finaltest +"); Archive::Tar->create_archive ("Bundle-FinalTest.tar.gz", COMPRESS_GZIP +, @fl);

      Enjoy, Have FUN! H.Merijn
        thanks H.Merijin i have used your code
      A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://929483]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-03-19 09:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found