Change the file extension for files in a folder?

后端 未结 5 1725
逝去的感伤
逝去的感伤 2020-12-05 00:31

I would like to change the extension of the files in specific folder. i read about this topic in the forum. using does ideas, I have written following code and I expect that

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-05 01:12

    import os

    dir =("C:\\Users\\jmathpal\\Desktop\\Jupyter\\Arista")
    for i in os.listdir(dir):
        files = os.path.join(dir,i)
        split= os.path.splitext(files)
        if split[1]=='.txt':
           os.rename(files,split[0]+'.csv')
    

提交回复
热议问题