in reply to Re^3: 7zip a folder
in thread 7zip a folder

Hi Soonix, It is working, Thanks! I am just wondering if there is a command to zip file and also delete what we've archived. Or we just zip files then to delete them using two steps. Thanks

Replies are listed 'Best First'.
Re^5: 7zip a folder
by soonix (Chancellor) on Nov 06, 2017 at 15:59 UTC
    You'd have to implement this yourself. It seems to me the creators of 7-zip aren't willing to implement this because it is too easy to destroy a freshly created archive after all the files are compressed and deleted.
      Basically, what I am doing now is to move all the files falling into my date range to a new folder which foldername is the timestamp of those files, then zip all the file under this folder, I could not get it through, because it is saying \$foldername\ the system cannot find the path specified.
      $date = strftime("%Y-%m-%d", localtime); mkdir my $foldername = "D:/log_script/Archive/$date"; my @cmd = 'D:/app/7-Zip/7z.exe', 'a', '-mx9', 'D:/log_script/Archive/target.zip', '$foldername/*.log' ); print 'about to execute: ', Dumper \@cmd; system @cmd;

        Have you printed @cmd before running it through system?

        If you have done so, you will see that single quotes do not interpolate variables. $forldername appears verbatim in your command.

        Most likely, you want to use double quotes instead:

        "$foldername/*.log",
      Hi Soonix, Can I also ask you what is the 9 meaning in -mx9? Thanks