import os
import shutil
def delete_dir(root_path):
case_list = os.listdir(path= root_path)
case_list.sort()
for case in case_list:
print("case = {}".format(case))
get_subdir = os.listdir(os.path.join(root_path, case))
for sub_dir in get_subdir:
shutil.move(os.path.join(root_path, case, sub_dir), os.path.join(root_path, sub_dir))
os.rmdir(os.path.join(root_path, case))
if __name__ == '__main__':
root_path = r'F:\\Hepatobiliary_surgery\\test'
delete_dir(root_path)
Python os处理 删除上一级目录并保存文件
最新推荐文章于 2023-09-23 09:33:15 发布