行走的蓑衣客

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
统计
 
复制代码
import threading
import time
import os
import tarfile


input_path = r"D:\jieyaqian"
out = r'D:\jieyahou'
classs = os.listdir(input_path)



def repress(folder, input_path, out):
    print(1, folder)
    ori_tif = os.path.join(input_path, folder)
    print(ori_tif)
    name = os.path.basename(ori_tif)
    print(name)
    # 解压单个文件
    if not os.path.exists(os.path.join(out, name)):
        os.makedirs(os.path.join(out, name))
        tf = tarfile.open(ori_tif)
        tf.extractall(os.path.join(out, name))

def single():
    print('begin-------------')
    for folder in classs:
        repress(folder, input_path, out)
    print('end-------------')

def multiple():
    print('begin-------------')
    threads = []
    for folder1 in classs:
        threads.append(
            threading.Thread(target=repress(folder1, input_path, out))
        )
    for thread in threads:
        thread.start()
    for thread in threads:
        thread.join()
    print('end-------------')


if __name__ == '__main__':
    start = time.time()
    multiple()
    end = time.time()
    print('single thread cost:', end - start, 'seconds')
复制代码

 批量解压zip文件

复制代码
import os
import zipfile
import pathlib


def unzip_file(zip_src, dst_dir):
    r = zipfile.is_zipfile(zip_src)
    if r:
        fz = zipfile.ZipFile(zip_src, 'r')
        for file in fz.namelist():
            if pathlib.Path(file).suffix == '.zip':
                print(os.path.join(dst_dir, file), os.path.join(dst_dir, pathlib.Path(file).parent))
                unzip_file(os.path.join(dst_dir, file), os.path.join(dst_dir, pathlib.Path(file).parent))
            fz.extract(file, dst_dir)
    else:
        print('This is not zip')

unzip_file(r"D:\test\加压数据\源数据\VOCdevkit.zip", r"D:\test\加压数据\解压后")
复制代码

 

posted on   行走的蓑衣客  阅读(159)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
 
点击右上角即可分享
微信分享提示