«

图片更名实例

时间:2021-11-18     作者:管理员     分类: 教程


# -- coding: utf-8 --

# @Time    : 2021/11/18 1:02

# @Author  : suxin

# @Email   : 208082474@qq.com

# @File    : os_test.py

# @Software: PyCharm



import os

import time

st = time.time()

path1 = r"C:\Users\suxin\Pictures"

ps = ['bmp', 'jpeg', 'gif', 'psd', 'png', 'jpg']

for root, dirs, files in os.walk(path1):

    # print(root, dirs, files)

    for p in ps:

        for x in files:

            if x.endswith(p):

                a = os.path.splitext(x)

                print(x)

                os.chdir(root)

                os.rename(root+"\"+x, a[0]+"_jycj"+a[-1])

et = time.time()

print(et-st)