Python script perfectly solves Linux environment decompression. zip file garbled problem

Source: Internet
Author: User
Tags python script

1, vi uzip (file name)
2. Copy the following Python program

1 #!/usr/bin/env python2 #-*-coding:utf-8-*-3 #uzip.py4  5 ImportOS6 ImportSYS7 ImportZipFile8  9 Print "processing File"+ sys.argv[1]Ten   OneFile=zipfile. ZipFile (Sys.argv[1],"R"); A  forNameinchfile.namelist (): -Utf8name=name.decode ('GBK') -     Print "extracting"+Utf8name thepathname =os.path.dirname (utf8name) -     if  notOs.path.exists (Pathname) andpathname!="": - os.makedirs (pathname) -data =file.read (name) +     if  notos.path.exists (utf8name): -fo = open (Utf8name,"W") + fo.write (data) A Fo.close atFile.close ()

3, chmod +x uzip
4,./uzip Xxxx.zip

Pro-Test effective,:)

Python script perfectly solves Linux environment decompression. zip file garbled problem

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.