in reply to 7zip a folder

Hello ytjPerl,

It seems that the fellow Monks have tried to assist you. Since you have not updated your question if you have resolved the issue/problem I will just add some minor notes, hopping that they will assist you.

There have been a few similar questions to yours, like Perl and 7zip and backticks and Caturing 7zip output with Perl. I also found a relevant module Archive::SevenZip, which should minimize the errors.

Read the questions, try to apply the module and let us know if it worked for you.

Hope this helps, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!

Replies are listed 'Best First'.
Re^2: 7zip a folder
by ytjPerl (Scribe) on Oct 31, 2017 at 16:58 UTC

    I saw this command

    Perl> open PIPE, '-|', '"\Program Files\7-Zip\7z.exe" e -so e:\UnxUtil +sSrc.zip 2>&1 1>nul' or die $@;;

    which can extract zip file.

    But I still do not know what is the syntax for compress folder. I move all the files into a folder then compress it.

      I'd suggest first reading the 7-zip help to learn how to use it's command line interface. You'll need to understand how to run the command outside of Perl before you can incorporate that command inside your Perl code.

      I believe that the general syntax that you're looking for is:

      "C:\Program Files\7-Zzip\7z.exe" a -tzip my_archive.zip C:\my_data\ -r

      However, putting that into your Perl code and trying to capture the output (STDOUT and/or STDERR) may be a challenge. I apologize for not being able to describe this using correct terminology. The 7z.exe is at times reusing lines in STDOUT to show progress. I could be wrong, but I think that behavior will causes challenges when trying to caputure output messages from the 7z.exe utility.

      I second dasgar's answer, especially the first paragraph. That said, I have compressed things using something like the following, which would compress all .txt files in current and subdirs into target.zip:
      ... use Data::Dumper; ... my @cmd = ( 'c:\Program Files\7-Zip\7z.exe', 'a', '-mx9', '-r', 'target.zip', '*.txt', ); print 'about to execute: ', Dumper \@cmd; system @cmd;
      The 7zip man page is not on their home page, but over there you can have a glance.
        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