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处理 删除上一级目录并保存文件的全部内容,更多相关Python内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复