Ubuntu 下解压 windows(GBK文件名) 压缩包的脚本

<span class="Comment">360doc 上找到的, 稍微改了一点点, 有效可用, python脚本</span>
<span class="Comment">#!/usr/bin/env python</span>
<span class="Comment"># -*- coding: utf-8 -*-</span>
<span class="PreProc">import</span> os
<span class="PreProc">import</span> sys
<span class="PreProc">import</span> zipfile

<span class="Function">print</span> <span class="String">&quot;Processing File &quot;</span> + sys.argv[<span class="Number">1</span>]

f = zipfile.ZipFile(sys.argv[<span class="Number">1</span>], <span class="String">&quot;r&quot;</span>)
<span class="Repeat">for</span> name <span class="Operator">in</span> f.namelist():
    utf8name = name.decode(<span class="String">'gbk'</span>)
    <span class="Function">print</span> <span class="String">&quot;Extracting &quot;</span> + utf8name
    pathname = os.path.dirname(utf8name)
    <span class="Conditional">if</span> <span class="Operator">not</span> os.path.exists(pathname) <span class="Operator">and</span> pathname != <span class="String">&quot;&quot;</span>:
        os.makedirs(pathname)
    data = f.read(name)
    <span class="Conditional">if</span> <span class="Operator">not</span> os.path.exists(utf8name):
        fo = <span class="Function">open</span>(utf8name, <span class="String">&quot;wb&quot;</span>)
        fo.write(data)
        fo.close
f.close()

发表评论

电子邮件地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据