Solved

How to zip and tar files in perl

Posted on 2004-09-13
8
949 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 6

Expert Comment

by:holli
ID: 12044846
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
ID: 12044926
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
ID: 12045031
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Assisted Solution

by:kandura
kandura earned 200 total points
ID: 12045335
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
 
LVL 6

Expert Comment

by:holli
ID: 12045772
rtfm holli, rtfm ;-)
0
 
LVL 18

Expert Comment

by:kandura
ID: 12046705
8^D
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 50 total points
ID: 12048809
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
ID: 12061258
Thanks all

vlearns
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…

733 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