7z 的命令行从存档内的特定文件夹中提取特定文件 [英] Command line for 7z to extract specific files from specific folders inside an archive

查看:32
本文介绍了7z 的命令行从存档内的特定文件夹中提取特定文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个 Python 脚本,我需要调用 7z 来提取保存在存档目录中的一些文件,而无需提取完整的存档.存档包含多个目录,我需要从特定目录中提取一些文件.

I'm writing a Python script where I need to call 7z to extract some files kept inside a directory in an archive without extracting the complete archive. The archive contains multiple directories and I need to extract some files from a particular directory.

假设abc.7z"是一个包含多个目录的存档,即temp"、windows"、system"、data".我想从目录system"中提取一些 .exe 文件只是因为这些 .exe 文件也可能存在于其他目录中,但我只对system"中的文件感兴趣.

Let's say, "abc.7z" is an archive which contains multiple directories, i.e "temp", "windows", "system", "data". I want to extract some .exe files from directory "system" only because those .exe files might be present in other directories too but I am interested only in the files from "system".

我只需要 7z 命令;我会弄清楚如何从脚本中调用 7z.感谢您的帮助.

All I need is the 7z command; I'll figure out how to call 7z from the script. Thanks for your help.

推荐答案

您可以在命令行的末尾指定文件/文件夹过滤器.检查 this 以获取有关 7zip 命令行命令和选项的更多详细信息.

You can specify a file/folder filter at the end of the command line. Check this for more details on 7zip command line commands and options.

7z.exe x [archive.7z] -o[output_dir] [filter]

例如7z.exe x abc.7z -aoa -oC:Temp system

您还可以从系统文件夹中指定特定类型的文件.例如system*.exe 将提取 system 目录中的所有 .exe 文件.

You can also specify files of a particular type from system folder. For e.g. system*.exe will extract all .exe files inside the system directory.

-aoa 选项用于覆盖模式.

要从 Python 调用它,您可以使用 subprocess 模块.类似的东西:

To call it from Python you can use subprocess module. Something like:

import subprocess

cmd = []
cmd.append(r'C:Program Files7-Zip7z.exe')
cmd.append('x')
cmd.append(archive)
cmd.append('-aoa')
cmd.append('-o{}'.format(dst_part))
cmd.append(file_folder_filter)
subprocess.call(cmd)

这篇关于7z 的命令行从存档内的特定文件夹中提取特定文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆