简体   繁体   中英

Extract All Zipped Files to Same Directory Using Python

我在单个目录中有大量压缩文件,我想解压缩并将它们保存到同一目录并与压缩文件同名。

Start with something like:

import glob
import os
import zipfile

zip_files = glob.glob('*.zip')

for zip_filename in zip_files:
    dir_name = os.path.splitext(zip_filename)[0]
    os.mkdir(dir_name)
    zip_handler = zipfile.ZipFile(zip_filename, "r")
    zip_handler.extractall(dir_name)

Sorry, I don't have time to test this code; any bug is left as an exercise for you.

[Updated with eumiro's suggestion]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM