Change the file extension for files in a folder?

后端 未结 5 1716
逝去的感伤
逝去的感伤 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:15

    You don't need to open the files to rename them, os.rename only needs their paths. Also consider using the glob module:

    import glob, os
    
    for filename in glob.iglob(os.path.join(folder, '*.grf')):
        os.rename(filename, filename[:-4] + '.las')
    

提交回复
热议问题