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)
图片名称命名小工具
最新推荐文章于 2022-11-16 17:56:45 发布