txt文件重命名

批量将txt文件重命名

import os
path1 = 'INbreast/FILENEW-TRUE'
path2 = 'INbreast/CC_image/CC'
path3 = 'INbreast/txt/CC'
f = 1
files1 = os.listdir(path1)
files2 = os.listdir(path2)
for file1 in files1:
    for file2 in files2:
        if file1[:8] in file2:
            if 'cal' in file1:
                os.rename(os.path.join(path1, file1), os.path.join(path3, file2[:-5]+'-cal.txt'))
            else:
                os.rename(os.path.join(path1, file1), os.path.join(path3, file2[:-5]+'-mass.txt'))
发布了315 篇原创文章 · 获赞 119 · 访问量 11万+

猜你喜欢

转载自blog.csdn.net/w144215160044/article/details/104915650