Python解压一个目录下的所有压缩包

2018-12-09  本文已影响24人  续袁

import zipfile

import tarfile

import os

import shutil

from globimport glob

import sys

def un_zip(path,file_name):

"""unzip zip file"""

    zip_file = zipfile.ZipFile(path+file_name)

    unzipDir = os.path.splitext(file_name)[0]

    print("unzipDir:", unzipDir)

'''

if os.path.isdir(unzipDir):

pass

else:

os.mkdir(unzipDir)

'''

    for namesin zip_file.namelist():

      print("names:",names)

      zip_file.extract(names,path)

   zip_file.close()

print(file_name +"解压完成!")

path='F:\matlab-project\Tracker\data\\video\\' #'F:/matlab-project/test/'

files = os.listdir(path)

for file_namein files:

print("file_name:",os.path.splitext(file_name)[1])

if os.path.splitext(file_name)[1] =='.zip':

print("file_name:",file_name)

un_zip(path,file_name)

上一篇 下一篇

猜你喜欢

热点阅读