今天,得到一个里面都是图片的文件夹,但是图片都没有后缀,因此想用Pythton批量地为所有的文件加上".jpg"的后缀,代码如下:

#-*- coding:utf-8 -*-
#重命名文件

import os

path = 'D:\pics'
for file_path  in os.listdir(path):
    if os.path.isfile(os.path.join(path, file_path)) == True:
        if file_path.find(".") < 0:
            new_name = file_path + ".jpg"
            os.rename(os.path.join(path, file_path), os.path.join(path, new_name))
print "done"

相关文章:

  • 2022-12-23
  • 2021-08-09
  • 2021-08-16
  • 2021-11-29
猜你喜欢
  • 2021-05-29
  • 2021-06-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
相关资源
相似解决方案