Zip files and delete them in base perl -
i want zip files of length , delete them once zipping successful. doing deletion of files not zipped. using below code. deleting part working fine zipping not happening.
i using base perl , can't use modules archive::zip
, io:compress::zip
.
sub actiononfile { my($filearray_ref, $action, $directory, $zipname) = @_; @filearray = @$filearray_ref; $action = uc($action); #set action string uppercase $cdt = ¤tdatetime; foreach $filename (@filearray) { if ($action eq "zipdel") { # zip , delete file $zipcommand = "wzzip -p -m \"$directory\\$zipname.$cdt.zip\" \"$directory\\$filename\""; open zip_process, "$zipcommand |" or $rcode=5; print logfile " error: opening zip delete process $filename: $! $?\n" if ($rcode == 5 || $!); while (<zip_process>) { $rcode=3 if ($_=~/error/i or $_=~/warning/i); # next line prevents standard winzip version info printing log $resultline = <rim($_) unless ($_=~/winzip\(r\) command line support add-on/ || $_=~/copyright \(c\) winzip international llc/); chomp($resultline); print logfile " ...$resultline\n" if ($resultline); } $zrc = close zip_process or $rcode=7; print logfile " error: closing zip delete process $filename: $! $?\n" if ($rcode == 7); # necessary error check open/close zip process if ($rcode == 3) { #if zip error print logfile " error: warning(s) and/or error(s) during zip/delete process $filename\n"; $rcode = 6; next; } undef $zipcommand; } elsif ($action eq "delete" && -f "$directory/$filename") { # verifies file , not directory > unlink not work correctly dirs $dresult = 0; $dresult = unlink "$directory\\$filename"; if ($dresult == 1) { #if unlink(delete) successful print logfile " ...deleted $filename $directory.\n"; } else { print logfile " error: during delete of $filename $directory: $! $?\n"; $rcode = 4; } undef $dresult; } elsif ($action eq "list" ) { print logfile " ...file found: $filename\n"; } } }