How to compress with 7zip instead of zip, code changing

后端 未结 2 539
野趣味
野趣味 2020-12-30 08:08

I have a code that compress every file in a specific folder with zip but I want to compress it with 7zip, so how to do ?

This is what I have so far:



        
相关标签:
2条回答
  • 2020-12-30 08:27

    There doesn't appear to be a good Python module for creating a 7z archive (despite what the documentation says, py7zlib can only read them).

    A workaround is to download the 7z SDK (http://www.7-zip.org/sdk.html) and use the 7zr executables that come with it via the subprocess module. 7z is in the public domain so you can carry this standalone program around without restriction.

    0 讨论(0)
  • 2020-12-30 08:34

    You can try the command line method

    import subprocess
    subprocess.call(['7z', 'a', filename+'.7z', filename])
    

    or for all files in folder

    subprocess.call(['7z', 'a', filename+'.7z', "*.*"])
    
    0 讨论(0)
提交回复
热议问题