使用 python 使用子进程从 7zip 存档中解压选定的文件
我目前正在使用 subprocess 使用 7zip 解压选择的文件或 zip 文件。我必须使用这种解包方法而不是 zipfile 模块,因为有时 zipfile 会损坏 shapefile。我当前的方法是:
try:
for file in os.listdir(downloads):
print file
expression2 = sevenzip + " e " +downloads + '\\' + file + " -oC:\Users\Oulton"
print expression2
#os.system(r"C:\Users\Oulton\7z e C:\Users\Oulton\install.zip -oC:\Users\Oulton")
subprocess.call(expression2)
except:
time.sleep(3)
traceback.print_exc()
但这并不方便,因为:
- 我只想解压某些 .shp 文件,而不是每个 zip 中的所有其他垃圾 文件
- 每次迭代都会打开和关闭 shell,我希望 shell 在整个过程中保持打开状态
- 我必须使用手动输入来使用此方法覆盖重复命名的文件
I am currently using subprocess to unpack a selection or zip files using 7zip. I have to use this unpacking method instead of the zipfile module because on occasion the zipfile corrupts shapefiles. My current method is:
try:
for file in os.listdir(downloads):
print file
expression2 = sevenzip + " e " +downloads + '\\' + file + " -oC:\Users\Oulton"
print expression2
#os.system(r"C:\Users\Oulton\7z e C:\Users\Oulton\install.zip -oC:\Users\Oulton")
subprocess.call(expression2)
except:
time.sleep(3)
traceback.print_exc()
But this is not convenient because:
- I only want to unpack certain .shp files and not all of the other junk in each zip
- A shell is opened and closed for each iteration, I would prefer the shell to stay open throughout
- I have to use manual input to overwrite duplicately named files using this method
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
7z e C:\Users\Oulton\install.zip -oC:\Users\Oulton" *.shp -r
3.
-i
和-x
可用于分别包含或排除要提取的特定文件。7z e C:\Users\Oulton\install.zip -oC:\Users\Oulton" *.shp -r
3.
-i
and-x
can be used to respectively include or exclude specific files for extraction.