import os
#设定文件路径
files = os.listdir('F:/PEK/PEK1-test')
#i=1
for filename in files:
path = 'F:/PEK/PEK1-test'+"/"+filename
print(path)
#对目录下的文件进行遍历
for subfile in os.listdir(path):
#判断是否是文件
if os.path.isfile(os.path.join(path,subfile))==True:
new_name = filename + "_" + "rest.nii.gz"
#设置新文件名
#new_name=file.replace(subfile,"%drest.nii.gz"%two)
#重命名
os.rename(os.path.join(path,subfile),os.path.join(path,new_name))
#i+=1
批量修改文件名为上级目录名字
最新推荐文章于 2024-07-20 11:43:46 发布