如何在没有 ini 和 zip 文件的情况下创建 zip 存档

How to create zip archive without ini and zip files

我有一个文件夹,其中包含:

bd.txt
/Config
/DLL
/Rapports
bx1478.ini
ARCH.zip

我想创建一个没有 ini 和 zip 文件的存档。 我尝试如下,但我得到一个空存档:

import subprocess
SZ_PATH_TMP = '../tmp'
SZ_PATH_WORK = '../work'
full_label_version = 'ARCH' 
subprocess.call(['7z', 'a', SZ_PATH_TMP+'/'+full_label_version+'.zip', SZ_PATH_WORK+'/* -xr!*.zip -xr!*.ini'])

当您将参数列表传递给 subprocess 时,每个选项都需要是一个单独的列表项。

import subprocess
SZ_PATH_TMP = '../tmp'
SZ_PATH_WORK = '../work'
full_label_version = 'ARCH' 
subprocess.call(
    ['7z', 'a', 
    SZ_PATH_TMP+'/'+full_label_version+'.zip',
    SZ_PATH_WORK+'/*,  '-xr!*.zip', '-xr!*.ini'])

如果您不确切知道 shell 如何将命令行分解为参数,可以将整个命令作为字符串传递给 shlex.split()