在Windows中重命名文件

2024-03-29 11:37:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我在Windows中有一堆文件有前缀和后缀需要删除。你知道吗

例如

[video] Home Video - 014 Sunday Night[480p] [x265] [robert].mkv
[video] Home Video - 015 Monday Night[480p] [x265] [robert].mkv
[video] Home Video - 016 Tuesday Night[480p] [x265] [robert].mkv

我想重命名这些文件,这样它会说

014 Sunday Night
015 Monday Night
016 Tuesday Night

我不介意使用PowerShell、Python、Bat或者Windows提供的任何东西。 我宁愿不下载第三方工具,但会考虑它,如果需要的话


Tags: 文件homewindowsvideorobert后缀重命名mkv
2条回答

您可以使用单个PowerShell cmdlet:

Get-ChildItem *.mkv | Rename-Item -NewName { $_.name -Replace '.*?(\d{3}.*?)\[.*?\.','$1.'}

您可以在python中读取带有“os”的文件,并用常规表达式替换名称:

读取文件:https://www.tutorialspoint.com/python/os_rename.htm

用python重命名文件:Rename multiple files in a directory in Python

使用regex删除文本:How to remove symbols from a string with Python?

相关问题 更多 >