Objective
Many times in Windows compressed file is no problem, but to Linux, there are garbled, very common. It used to `unzip -O GBK filename.zip`
be done under Ubuntu. After the change of Fedora, temporarily did not find garbled compressed files. Download a book in the evening CD, and ran into garbled. The method before the attempt did not succeed. See the next unzip help, no-o that parameter = = just find a way to use Python solution, share.
Create a new file with a '. py ' suffix and copy and paste the code directly:
#!/usr/bin/env python
#-*-coding:utf-8-*-
import os
import sys
import zipfile
print ' processing File "+ sys.argv[1]
file=zipfile. ZipFile (Sys.argv[1], "R");
For name in File.namelist ():
utf8name=name.decode (' GBK ')
print "extracting" + utf8name
pathname = Os.path.dirname (utf8name)
if not os.path.exists (pathname) and pathname!= "":
os.makedirs (pathname)
data = File.read (name)
if not os.path.exists (utf8name):
fo = open (Utf8name, "w")
fo.write (data)
Fo.close
File.close ()
Execute the zip file and the lovely Chinese comes out.
Python filename. py needs to extract the filename. zip
Summarize
Well, this problem is so simple to solve, we have learned it? Hope this article for everyone's study or work can bring some help, if there is doubt you can message exchange.