As documented, use the second parameter on the addFile() method to force a different name, which (not documented) can include a name with no path. I leave it as an exercise for the reader to figure out how to determine the base filename without the path for any given file. Sample attached.
#!/usr/bin/perl use Archive::Zip; use strict; my $TRUE = 1; my $FALSE = 0; foreach my $addtyp (qw /yespath nopath/) { # Hard-code test values my $os_nam = $^O; # Operating system name my $unisep = '/'; # *nix directory separato +r my $winsep = "\\"; # Windows directory sepa +rator my $subdnm = "sub1"; # Subdirectory name my $shtfnm = 'test.dat'; # Filename with no path my $zipfnm = "test-$addtyp.zip"; # ZIP filename my $zipobj = ''; # ZIP object pointer my $newflg = $TRUE; # Was this a new ZIP fi +le? # Set up test environment my $dirsep = $unisep; # Assum *nix until proven + otherwise if ($os_nam =~ /windows|win\d+/i) { # Appears to be Windows $dirsep = $winsep; } unlink $zipfnm; # Do not care if nonext +ant mkdir $subdnm; # Do not care if extant my $addfnm = "$subdnm$dirsep$shtfnm"; # Filename with path to a +dd open ADDFIL, ">$addfnm"; print ADDFIL "This is a test.\n"; close ADDFIL; # Perform test $zipobj = Archive::Zip->new(); if ($addtyp =~ /yespath/) { my $addret = $zipobj->addFile($addfnm); } else { my $addret = $zipobj->addFile($addfnm, $shtfnm); } my $wriret = $zipobj->writeToFileNamed($zipfnm); } exit;

In reply to Re: Question on Zip::Archive by marinersk
in thread Question on Zip::Archive by biswanath_c

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.