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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |