批量文件名替换小工具

最近下载了一些动漫,每个文件名都带着广告,强迫症的我怎么能忍,几百个文件要改到啥时间,必须造它。

1、首先写代码 

创建文件rename.py

import os
import sys
import typer

main = typer.Typer()

CUR_PATH = os.getcwd()

@main.command()
def replace_name(src: str = typer.Argument(..., help="替换源内容"),
                 dst: str = typer.Argument("", help="替换目标内容"),
                 count: int = typer.Option(-1, "--count", "-c", help="替换次数"),
                 depth: int = typer.Option(0, "--depth", "-d", help="遍历目录深度[0当前目录 1当前目录及子目录 ...]")
                ):

    # 遍历当前目录下的所有文件
    for root, dirs, files in os.walk(CUR_PATH, topdown=True):

        if root.count(os.sep) - CUR_PATH.count(os.sep) > depth:
            continue
        for name in files:
            if src and src in name:
                src_name = os.path.join(root, name)
                dst_name = os.path.join(root, name.replace(src, dst, count))
                os.rename(src_name, dst_name)
                print(f"==={src_name}\n==>{dst_name}\n")
  

if __name__ == "__main__":
    main()

2、打包成exe程序

pyinstaller -F rename.py

3、配置环境变量

注意:打包程序的时候注意命名,不要跟系统或其它的名称重名,可以加个自己的前缀。

把打包好的程序,放在我指定的工具目录E:/common,然后配置系统环境变量

4、测试

在需要重命名文件夹中,按住shift+鼠标右键 在此处打开命令行窗口

rename "[人人影视字幕组]"

完美

 

🌐本文链接:https://wizops.net/archives/202404/327.html(转载时请注明本文出处及文章链接)
⚠️本站部分资源文章出自互联网收集整理,本站不参与制作,如果侵犯了您的合法权益,请联系本站我们会及时删除。
⚠️本站资源仅供研究、学习交流之用,若使用商业用途,请购买正版授权,否则产生的一切后果将由下载用户自行承担。
💌联系方式: [email protected]
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇