Solved

How to zip and tar files in perl

Posted on 2004-09-13
8
922 Views
Last Modified: 2006-11-17
Hi i have a list of files beginning with a and ending with underscore

like a*_.exe

i need to tar or zip them from within a perl script...(not at the command line)

how to do this on windows...

i want to unzip/untar these on a unix platform and extract them to a folder on unix machine ...how do i do this...

thanks
0
Comment
Question by:Vlearns
8 Comments
 
LVL 6

Expert Comment

by:holli
Comment Utility
Do you want to use gzip and tar - programs or do you prefer to use
Archive::Zip and Archive::Tar - Modules?
0
 
LVL 6

Expert Comment

by:holli
Comment Utility
anyway, this is how to archive the files:

use strict;

use Archive::Tar;
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );

my $tar = Archive::Tar->new();
$tar->add_files(glob ("c:/temp/*.exe"));
$tar->write("file.tar");

my $zip = Archive::Zip->new();
my $member = $zip->addFile("file.tar");
die 'write error' unless $zip->writeToFileNamed( 'file.tar.gz' ) == AZ_OK;
0
 
LVL 6

Accepted Solution

by:
holli earned 250 total points
Comment Utility
and how to extract:

use strict;

use Archive::Tar;
use Archive::Zip qw( :ERROR_CODES :CONSTANTS );

my $zip = Archive::Zip->new();

die 'read error' unless $zip->read( 'file.tar.gz' ) == AZ_OK;
$zip->extractMember('file.tar');

my $tar = Archive::Tar->new ("file.tar");
$tar->extract( $tar->list_files() );
0
 
LVL 18

Assisted Solution

by:kandura
kandura earned 200 total points
Comment Utility
Archive::Tar can also compress files itself (using Compress::Zlib / IO::Zlib, whichever is part of your perl installation), so there's no need to do the Archive::Zip stuff.

use strict;
use Archive::Tar;
my $tar = Archive::Tar->new();
$tar->add_files(<a*_.exe>);
$tar->write("file.tar.gz", 1, 9); ### filename, compressed, maximum_compression
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 6

Expert Comment

by:holli
Comment Utility
rtfm holli, rtfm ;-)
0
 
LVL 18

Expert Comment

by:kandura
Comment Utility
8^D
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 50 total points
Comment Utility
If you don't want to use any modules (I would recommend that you do use a module), you can do:

system "zip files.zip a*_.exe" and die "Can not zip files $!\n";
0
 

Author Comment

by:Vlearns
Comment Utility
Thanks all

vlearns
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now