python解压压缩包

import os
import shutil

def scan_file():
    for f in os.listdir(): #程序运行文件和需压缩的文件需同一目录
        if f.endswith('.zip'):
            return f

def unzip_it(f):
    folder_name = f.split('.')[0]
    target_path = './' + folder_name
    os.makedirs(target_path)
    shutil.unpack_archive(f,target_path)

def delete(f):
    os.remove(f)

while True:
    zip_file = scan_file()
    if zip_file:
        unzip_it(zip_file)
        delete(zip_file)

猜你喜欢

转载自blog.csdn.net/zhuchuana/article/details/84755740