图片名称命名小工具

import os
import shutil
import tkinter as tk
from tkinter import filedialog,simpledialog

root = tk.Tk()
root.withdraw()

# file_path = filedialog.askopenfilename()#选择文件
file_name = filedialog.askdirectory()#选择文件夹
spu_id = simpledialog.askstring('spu_id','spu_id',initialvalue='')
# print(file_path)
# print(spu_id)


# file_name = input("输入文件路径:")
# spu_id = input("输入spu_id:")
file_list = os.listdir(file_name)
new_file = os.path.join(file_name, spu_id)
if not os.path.isdir(new_file):
    os.mkdir(new_file)
i = 0
for lst in file_list:
    origin_path = os.path.join(file_name, lst)
    if os.path.isfile(origin_path):
        i += 1
        img1, img2 = lst.split('.')
        if img2 == 'DS_Store':
            i-=1
            continue
        image_new_name = spu_id + '-' + str(i) + '.' + img2
        # new_file_rename = os.path.join(new_file, lst)
        new_file_rename_end = os.path.join(new_file, image_new_name)
        # shutil.copy(origin_path,new_file)
        shutil.copy(origin_path,new_file_rename_end)
        # os.rename(new_file_rename,new_file_rename_end)
        # print(origin_path)
# print(file_list)

用此打包:https://www.jianshu.com/p/75da02dfa1a3

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值