欢迎光临散文网 会员登陆 & 注册

删除天正Tn后缀

2022-06-20 17:27 作者:翼羽四方  | 我要投稿

import os

import re

import time


#去除文件的天正后缀

def Delete_tn():

    topPath = input('请输入需要删除天正后缀的文件夹路径:\n')

    myStr=["_*[tT][0-9]+","[vV][0-9]+"]

    newName=""

    for n in myStr:

        pattern = re.compile(n)

        #获取该目录下所有文件,存入列表中

        for root,dirs,files in os.walk(topPath):

            if(len(files)>0):

                for fileName in files:

                    os.chdir(root)

                    if(pattern.findall(fileName)):

                        newName =re.sub(n,"",fileName,0)

                        if(os.path.exists(newName)):

                            #os.remove(newName)

                            print("或重名文件:"+os.path.realpath(newName))

                            break

                        else:

                            print(os.path.realpath(fileName)+'=====>'+ newName)

                            os.rename(fileName,newName)


Delete_tn()


删除天正Tn后缀的评论 (共 条)

分享到微博请遵守国家法律