How to rename a file using Python

后端 未结 12 1742
借酒劲吻你
借酒劲吻你 2020-11-22 13:47

I want to change a.txt to b.kml.

12条回答
  •  旧巷少年郎
    2020-11-22 14:24

    File may be inside a directory, in that case specify the path:

    import os
    old_file = os.path.join("directory", "a.txt")
    new_file = os.path.join("directory", "b.kml")
    os.rename(old_file, new_file)
    

提交回复
热议问题