Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

by $code or die (Deacon)
on Apr 11, 2001 at 20:06 UTC ( [id://71715]=sourcecode: print w/replies, xml ) Need Help??
Category: Utility Scripts
Author/Contact Info Simon Flack - $code or die
Description: I wanted to find a simple command line TAR\GZ program for Windows to GZip my modules for uploading to CPAN. But I couldn't find one I liked.

Of course there is always cygwin which I urge everyone to download who use "explorer.exe" as a shell. It's only a small download.

However, this fitted my needs. Please let me know any comments or improvements.

Update: You might also want to check out btrott's script which does the same thing but also stores the path. I didn't see this before I posted mine.
use Archive::Tar;
use Compress::Zlib;
use File::Find;

Syntax() unless @ARGV;

my $tar = Archive::Tar->new();

     find( { wanted => sub {    $tar->add_files($_);    } }, $ARGV[1])

$tardata = $tar->write();

if ($ARGV[2]) {
    open (GZIP, ">" . $ARGV[0] . ".tar.gz");
        my $gz = gzopen(\*GZIP, "wb");
        print $gz->gzwrite($tardata);
} else {
    my $tardata;
    open (TAR, ">" . $ARGV[0] . ".tar");
    print TAR $tardata;
    close (TAR);

sub Syntax {
print <<eof;

TAR and optionally GZIP a directory. [tar_name] [dir_2_tar] [GZIP]

e.g. example /tmp/example 1
will produce example.tar.gz

Replies are listed 'Best First'.
by $code or die (Deacon) on Apr 11, 2001 at 20:28 UTC
    Please note, that if you use this on anything public - PLEASE PLEASE think about using "perl -T" and untainting the user input. The only reason I don't have it in the code above is because I wrote this to do a specific thing and it was only going to be me that used it.

    $ perldoc perldoc

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://71715]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-07-25 10:16 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.