ubuntu python unzip主目录以及子目录

# 解压主目录以及子目录下zip文件到各自目录,并删除zip
import os
dir_name = "/home/data/"
def unzipAllFiles(dir_name):
    listOfFile = os.listdir(dir_name)
    allFiles = list()
    for entry in listOfFile:
        fullPath = os.path.join(dir_name, entry)
        if os.path.isdir(fullPath):
            allFiles = allFiles + unzipAllFiles(fullPath)
        else:
            if os.path.splitext(fullPath)[1] == '.zip':
                allFiles.append(fullPath)
                os.system('unzip -n ' +fullPath+ ' -d '+ dir_name + '; rm -rf ' + fullPath)

版权声明:本文为qq_41222313原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。