Preface
Many times in Windows to compress the file is not a problem, but to Linux, there is garbled, very common. In the past under Ubuntu, `unzip -O GBK filename.zip` it can be done. After changing fedora, no garbled compressed files have been found for the time being. In the evening to download a book CD-ROM, and encountered garbled. The previous method did not succeed. Looked at the next unzip help, did not-o that parameter = = just find a way to solve with Python, share under.
To create a new '. py ' suffix file, copy and paste the code directly:
#!/usr/bin/env python#-*-coding:utf-8-*-import osimport sysimport 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.closefile.close ()
Execute unzip the zip file, the cute Chinese will come out.
Python file name. py file name to unzip. zip
Summarize
Well, the problem is so easy to solve, everyone has learned it? Hope this article to everyone's study or work can bring certain help, if there is doubt you can message exchange.