Solved

How to zip and tar files in perl

Posted on 2004-09-13
8
928 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
perl script help 12 104
Rename file based on contents in the file? 3 80
PERL variable conundrum 9 89
Awk Question 2 123
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

919 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

14 Experts available now in Live!

Get 1:1 Help Now