# 将3d slicer生成的标签的文件名_Segmentation除去
import os
if __name__ == '__main__':
work_dir = "D:/airway_datasets/train_label_nii_enhence"
"""
这个文件夹里面的文件名都是: CASE01_seg.nii
CASE02_seg.nii
...
现在我全都要修改为: CASE01.nii
CASE02.nii
"""
filename_list = os.listdir(work_dir)
for file_name in filename_list:
new_name = file_name.split('_')[0]+'.nii' # 得到新的文件夹名
# print(new_name)
new_file_path = os.path.join(work_dir,new_name)
cur_file_path = os.path.join(work_dir,file_name)
# print(cur_file_path,new_file_path)
os.rename(cur_file_path,new_file_path) # 核心语句
python批量重命名文件
最新推荐文章于 2023-08-01 22:34:55 发布