I'm reusing a perl scrip to zip file from a directory and move zipped file to another directory. All works well except the directory path is included in the .zip file. example: result is /xyz/data/filename.txt I just want filename.txt in my zip file. I'm new to Perl and haven't been able to sort this out. here's my code:

#!/bin/perl -w # Author - Unknown # Date - 3/30/2009 # ARGV[0] = zipfile name # ARGV[1] = directory of files # ARGV[2] = output directory for zip file use Archive::Zip qw(:ERROR_CODES :CONSTANTS); use File::Copy; die "usage: $0 zipfile.zip direcotry [...]\n" if (scalar(@ARGV) < 3); ($sec,$min,$hour,$mday,$mon,$year) = localtime(time); $year+= 1900; $mon += 01; my $zipName = sprintf "$ARGV[0]_%04d%02d%02d%02d%02d%02d.zip", $year,$ +mon,$mday,$hour,$min,$sec; my $indir = $ARGV[1]; my $outdir = $ARGV[2]; my @files = <$indir*>; my $count = @files; if($count > 0){ my $zip = Archive::Zip->new(); foreach my $memberName (map { glob } $indir) { if (-d $memberName ) { if($zip->addFile( $memberName ) != AZ_OK){ #or sendalert(); $message = "Can't add file $memberName\n";} } } my $status = $zip->writeToFileNamed($zipName); if ($status != AZ_OK){ $message = "Can't add file to $zipName\n"; } else { move($zipName, $outdir) or die(qq{failed to move <br>$zipName -> + $outdir}); } foreach my $file (@files) { #print "$file\n"; unlink $file; #system("DEL $file"); } exit $status; }

In reply to Zip without dir path by enovak16

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.