我有一个代码用zip压缩特定文件夹中的每个文件,但我想用7zip压缩它,那该怎么办?
这是我到目前为止:
for date in dict_date:#zipping folders and get same name like the folder
with ZipFile(os.path.join(src, '{0}.7z'.format(date)), 'w') as myzip:
for subFolder in dict_date[date]:
for fil in os.listdir(os.path.join(src, date, subFolder)):
if not fil.endswith('.7z'):
myzip.write(os.path.join(src, date, subFolder, fil))
Run Code Online (Sandbox Code Playgroud)
您可以尝试命令行方法
import subprocess
subprocess.call(['7z', 'a', filename+'.7z', filename])
Run Code Online (Sandbox Code Playgroud)
或者对于文件夹中的所有文件
subprocess.call(['7z', 'a', filename+'.7z', "*.*"])
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24598 次 |
| 最近记录: |