找回密码
 立即注册

QQ登录

只需一步,快速开始

微信登录

只需一步,快速开始

楼主: gsm123

批量改文件名添加前缀

[复制链接]

0

主题

6

回帖

11

积分

新手上路

积分
11
发表于 3 天前 | 显示全部楼层
软件有病毒

1216

主题

257

回帖

4804

积分

超级版主

积分
4804
 楼主| 发表于 3 天前 | 显示全部楼层

import tkinter as tk
from tkinter import filedialog, messagebox
import os

def select_dir():
    path = filedialog.askdirectory()
    dir_var.set(path)

def run_add_prefix():
    folder = dir_var.get().strip()
    pre_text = prefix_var.get().strip()
    if not folder:
        messagebox.showwarning("提醒", "请先选择文件文件夹")
        return
    if not pre_text:
        messagebox.showwarning("提醒", "请输入要添加的前缀文字")
        return

    num = 0
    for file_name in os.listdir(folder):
        old_full = os.path.join(folder, file_name)
        # 只处理文件,跳过文件夹
        if os.path.isfile(old_full):
            new_name = f"{pre_text}{file_name}"
            new_full = os.path.join(folder, new_name)
            os.rename(old_full, new_full)
            num += 1
    messagebox.showinfo("完成", f"成功处理 {num} 个文件")

# 窗口布局
root = tk.Tk()
root.title("批量添加前缀工具")
root.geometry("460x200")

dir_var = tk.StringVar()
prefix_var = tk.StringVar(value="解锁素材_")

tk.Label(root, text="目标文件夹:").pack(pady=(10,0))
frame1 = tk.Frame(root)
frame1.pack()
tk.Entry(frame1, textvariable=dir_var, width=35).pack(side="left")
tk.Button(frame1, text="选择", command=select_dir).pack(side="right")

tk.Label(root, text="添加前缀文字:").pack(pady=(8,0))
tk.Entry(root, textvariable=prefix_var, width=40).pack()

tk.Button(root, text="开始批量添加前缀", bg="#0078d7", fg="white", command=run_add_prefix).pack(pady=20)

root.mainloop()
源码给你 ,哪来的病毒
全字库版块解压密码:kuoge.vip     kuoge     kuo-acc    feige

9

主题

123

回帖

382

积分

中级会员

积分
382
发表于 3 天前 | 显示全部楼层
谢谢分享

0

主题

30

回帖

234

积分

中级会员

积分
234
发表于 前天 13:30 | 显示全部楼层
6666666666666666666666

1

主题

617

回帖

1044

积分

金牌会员

积分
1044
发表于 前天 18:58 | 显示全部楼层
感谢分享!!

0

主题

177

回帖

1024

积分

金牌会员

积分
1024
发表于 前天 19:07 | 显示全部楼层
感谢分享

0

主题

49

回帖

271

积分

中级会员

积分
271
发表于 昨天 10:52 来自手机 | 显示全部楼层
看看能不能用的,是电脑还是手机的

1

主题

198

回帖

231

积分

中级会员

积分
231
QQ
发表于 昨天 12:06 | 显示全部楼层
11111111111111111111111111111111111111

2

主题

32

回帖

213

积分

中级会员

积分
213
发表于 昨天 20:56 | 显示全部楼层
1111111111111111111111111111111111111111111111
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

东海论坛VIP会员

Archiver|手机版|小黑屋|东海手机维修论坛

GMT+8, 2026-6-15 08:10 , Processed in 0.076526 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表