更改文件后缀,将txt转换成xml格式文件

xiaoxiao2025-07-07  7

import os files = os.listdir("D:\\JustForNLP\\script\\contentAll")#列出当前目录下所有的文件 # D:\JustForNLP\script\contentAll for filename in files: portion = os.path.splitext(filename)#分离文件名字和后缀 print(portion) if portion[1] ==".txt":#根据后缀来修改,如无后缀则空 newname = portion[0]+".xml"#要改的新后缀 os.chdir("D:\\JustForNLP\\script\\contentAll")#切换文件路径,如无路径则要新建或者路径同上,做好备份 os.rename(filename,newname)

 

转载请注明原文地址: https://www.6miu.com/read-5032723.html

最新回复(0)