import os
import shutil
import rarfile
import zipfile
import re
def main(target_path):
for root, dirs, files in os.walk(target_path):
now_dir = root # 解压后的存放目录
for file in files:
path = os.path.join(now_dir, file)
path_out = os.path.join(now_dir, 'down', file.split('.')[0])
if '.rar' in file:
rf = rarfile.RarFile(path) # 待解压文件
rf.extractall(path_out) # 解压指定文件路径
print(file,":OK")
if '.zip' in file:
z = zipfile.ZipFile(path)
z.extractall(path_out) # path为解压路径,解包后位于该路径下
print(file,":OK")
if __name__ == '__main__':
target_path = "dongtai/"
main(target_path)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)