Personal tools
You are here: Home 博客群 潘俊勇的Blog 2006 2006-12 当winrar不听话的时候
Log in


Forgot your password?
Recent Comments
 如何申请PLONE空间? (xuc2013) 2008-08-25
 我的修改,支持中文字体和换行 (Anonymous User) 2008-08-08
  (oSky) 2007-10-30
 得有银哪! (Zoomq) 2007-10-25
 晕菜 (Anonymous User) 2007-10-21
 
Document Actions

当winrar不听话的时候 当winrar不听话的时候

Submitted by panjy. on 2006-12-28 05:38. Python
由于文件编码差异,winrar不能解压缩来自linux上的文件 :-(

由于文件编码差异,winrar不能解压缩来自linux上的文件 :-(

由于硬件支持的问题,俺的本本还是在跑windows。这次需要从我们的服务器下载些文件。

于是 tar czf a.tgz .... 打了个包,下载下来。

但是在windows上,用winrar却解压不成,因为linux上是utf8的编码,而windows只理会gb编码。

找了半天winrar的选项,也没发现文件名编码转换的功能,生气中...

但是托python的福,其实只要4行脚本就可以解决问题了:

>>> import tarfile
>>> t = tarfile.open(r'a.tgz', 'r:gz')
>>> for i in t:
...    i.name = unicode(i.name)
...    t.extract(i)

需要注意的是:

  1. 我用的是python2.4
  2. 需要调整site.py中的默认编码: encoding = "utf-8"

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: