?
Solved

How to zip and tar files in perl

Posted on 2004-09-13
8
Medium Priority
?
969 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 1000 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 18

Assisted Solution

by:kandura
kandura earned 800 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 200 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
Six Sigma Control Plans
Suggested Courses

777 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