Python 批量操作文件,批量解压缩

# 批量操作文件,批量解压缩
import os
import shutil
import rarfile
import re


def main(target_path):
    # print(os.listdir(target_path))
    for root, dirs, files in os.walk(target_path):
        now_dir = root  # 解压后的存放目录
        for file in files:
            if ".avi" in file:
                path = "G:\编程资料\视频课程\黑马程序员_张孝祥_Java高新技术\AVI"
                shutil.move(now_dir+'\\'+file, path)

        #     if ".rar" in file:
        #         path = now_dir + "\\" + file
        #
        #         # strinfo = re.compile('高清视频')
        #         # path2 = strinfo.sub('AVI', now_dir)
        #         # # now_dir.replace("高清视频", "1")
        #
        #         rf = rarfile.RarFile(path)  # 待解压文件
        #
        #         rf.extractall(now_dir)  # 解压指定文件路径
        #         print(file,":OK")
        # print(root)
        # print(dirs)
        # print(files)


if __name__ == '__main__':
    # target_path = "G:\编程资料\视频课程\撩课学院-JavaEE学科"
    target_path = "G:\编程资料\视频课程\黑马程序员_张孝祥_Java高新技术"
    main(target_path)

你可能感兴趣的:(Python)