Windows 下使用 Powershell 批量重命名文件
Mar 18, 2018·
·
1 min read
Shenghui (Samuel) Gu
当我们下载了一部电视剧或是动漫时,通常文件名非常长,会包含视频的分辨率、字幕组等信息,但是我们通常只会关心这是第几集。。。
于是就开始寻找 Windows 下批量重命名的方法。 虽然 Windows 下的命令行没有 Linux 下方便,但是还是提供了必备的功能。
以下就是通过 Powershell 实现批量正则重命名文件。
Get-ChildItem *.mp4 | Rename-Item -NewName { $_.name -replace '.*Vol\.([0-9]{1}).*', 'Video_$1.mp4' }
其中管道前是列出所有 mp4 文件。
Rename-Item 的一般形式是 Rename-Item -Path <String> -NewName <String> 。
大括号内是通过正则替换字符串。
另外 Get-ChildItem 的别名是 ls , Rename-Item 的别名是 rni 。

Authors
Shenghui (Samuel) Gu
(he/him)
Postdoctoral Researcher
Postdoctoral Researcher at the University of Ottawa specializing in Trustworthy AI and Software Engineering, holding a Ph.D. from Nanjing University.
Research lies at the intersection of AI Safety and System Reliability, with deep expertise spanning LLM-driven testing, search-based software engineering for autonomous systems, and AIOps for distributed architectures.
Dedicated to developing rigorous, interpretable, and scalable methodologies that leverage generative AI to solve complex validation challenges in safety-critical and large-scale industrial systems.