Python 目录下文件重命名

本文介绍了如何使用Python在Windows 7环境下,针对按数字编号但不连贯的mp3文件进行重命名,以便于顺序播放。文章提供了一个完整的程序,包括主要的重命名逻辑和辅助类Tl_class_frame的代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Python 目录下文件重命名

#Time: 2020/04/27
#Author: Xiaohong
#运行环境: OS: Windows 7
#  Python: 3.7

背景: 有时从网络下载的mp3文件,有按数字编号,但没有考虑到字符排序,会造成收听时不连贯,故用如下过程重命名,方便收听..如下是完整程式:

效果图为:

主程式为:

# -*- coding:utf-8 -*-
import tkinter as tk
from tkinter.ttk import *
from tkinter import ttk
from Tl_class_frame import *
import os
import time
from tkinter.filedialog import askopenfilename
from shutil import copy
import re

class PiMain(object):
    #设计UI 界面
    def setupUI(self):
        v = View(self.root, kind='日', orient=tk.VERTICAL)
        v.v1['width'] = 120

        # #增加按钮,用来 OS
        vButton = tk.Button(v.v1,text='待扩展1',width=11)
        vButton.place(anchor=tk.W,relx=0.1,rely=0.2)

        vButton = tk.Button(v.v1, text='待扩展2', width=11)
        vButton.place(anchor=tk.W, relx=0.1, rely=0.3)

        vButton = tk.Button(v.v1, text='待扩展3', width=11)
        vButton.place(anchor=tk.W, relx=0.1, rely=0.4)

        v_right = View(v.v2, bg='blue',kind='日', orient=tk.HORIZONTAL)
        v_right.v1['height'] = 100

        # #增加Label,用来
        tk.Label(v_right.v1,text='文件夹路径:').pack(side=tk.LEFT)
        self.file1=tk.StringVar()        
        tk.Entry(v_right.v1,width=50,textvariable=self.file1).pack(side=tk.LEFT)
        vButton = tk.Button(v_right.v1, text='...', width=3,command=self.getfile)
        vButton.pack(side=tk.LEFT)
        vButton = tk.Button(v_right.v1, text='重命名', width=8,command=self.renamefile)
        vButton.pack(side=tk.LEFT)

        v_right2 = View(v_right.v2, bg='bl
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值