Python calls 7zip command for decompression

Source: Internet
Author: User

Python calls 7zip command to implement file batch decompression

1. Enter the path where the compressed file is located

2. You can modify the extracted file path and the type of decompression required in the code, include, unzip all the files in the MP4 format below the folder.

3.cmd refers to the python call DOS command, followed by the x-r these are all reference 7zip use book, and extract folders under all the MP4 end of the file, put the file into e-disk, test the new folder under the Decompression folder

#call the 7z command to extract files in bulkImportOsfolder_name= Input ("Please enter a folder:") Os.chdir (folder_name) file_names= Os.listdir ("./") forNameinchFile_names:Print("is not a file:", Os.path.isfile (name))ifos.path.isfile (name): Name=Os.path.abspath (name)#returns a tuple, the second element of a tuple is an extension        ifOs.path.splitext (name) [1] = =". zip": cmd='\ "C:\\Program files\\7-zip\\7z.exe\" x \ "{0}\"-oe:/test decompression/new *.mp4-r'. Format (name) os.popen (CMD)

Python calls 7zip command for decompression

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.