首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用python使用子进程从7 7zip档案中解压缩选定的文件

使用python使用子进程从7 7zip档案中解压缩选定的文件
EN

Stack Overflow用户
提问于 2012-02-03 15:11:50
回答 1查看 3.1K关注 0票数 1

我目前正在使用子进程来解压选择或压缩文件使用7zip。我必须使用这个解压缩方法,而不是zipfile模块,因为有时use文件会破坏shapefile。我目前的方法是:

代码语言:javascript
复制
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()

但这并不方便,因为:

  1. I只想解压缩某些.shp文件,而不是每个zip
  2. 中的所有其他垃圾打开和关闭每次迭代,我希望shell在整个
  3. 中保持打开--我必须使用手动输入来覆盖重复命名的文件,使用这种方法
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-02-03 15:34:28

  1. 7z e C:\Users\Oulton\install.zip -oC:\Users\Oulton" *.shp -r
  2. Use Windows的for循环以重用相同的shell:http://www.robvanderwoude.com/for.php

3.

代码语言:javascript
复制
-ao (Overwrite mode) switch
Specifies the overwrite mode during extraction, to overwrite files already present on disk.

-i-x可分别用于包含或排除用于提取的特定文件。

代码语言:javascript
复制
7z e C:\Users\Oulton\install.zip -oC:\Users\Oulton -ir!*.shp -ir!*.mxd -ir!*.shx -ir!*.sbn -ir!*.dbf -ir!*.xml
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9130873

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档