python批量解压.tar文件

import tarfile
from glob import glob
import os
import cv2
def un_tar(file_name):
    """解压tar"""
    print(file_name)
    tar = tarfile.open(file_name)
    names = tar.getnames()
    print(names)
    for name in names:
        tar.extract(name, os.path.dirname(file_name)+"/result/")
    tar.close()

if __name__=="__main__":
    floder="D:/DataSet/likuan/quality/0414-4_NANLING_guangzhou_hddb_/*.tar"
    for i in glob(floder):
       print(i)
       un_tar(i)

你可能感兴趣的:(python批量解压.tar文件)