tif图批量重命名操作

纯项目要求文件命名格式,真SB

import os,re


def getName(path):
    # print(path)
    file_list=os.listdir(path)
    for file in file_list:
        # print(file)
        path2=path+'\\'+file
        # print(path2)
        file_list2=os.listdir(path2)
        for file2 in file_list2:
            # print(file2)
            path3=path2+'\\'+file2
            # print(path3)
            file_list3=os.listdir(path3)
            for file3 in file_list3:
                # print(file3)
                if file3.split('.')[1]=='tif':
                    # print(path3 +'\\'+file3)
                    p1=path3 +'\\'+file3
                    # print('p1=',p1)
                    # print(file3)
                    new_name = re.findall("\((.*?)\)",file3)
                    if new_name != []:
                        if new_name[0]=='必应':
                            new_name='biying'
                        else:
                            new_name=new_name[0]
                        # print('new_name=',new_name)
                        # p_2_1=path+'\\result\\'+file2+'\\'+new_name
                        # print('p_2_1=',p_2_1)
                        # print(p1)
                        p2=path+'\\result\\'+new_name+'\\'+new_name+'.tif'
                        # print('p2=',p2)
                        p2_1=path+'\\result\\'+new_name
                        # print('p2_1=',p2_1)
                        # print('p1=', p1)
                        os.makedirs(p2_1, exist_ok=True)

                        os.rename(p1,p2)


if __name__ == '__main__':
    path=input('请输入要重命名的路径:')
    getName(path)
    # getName('E:\data\data5')


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值