使用 Regex/Powershell 重命名文件 [英] Use Regex / Powershell to rename files
本文介绍了使用 Regex/Powershell 重命名文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何重命名以下文件(新 => 旧):
How does one rename the following files (New => Old):
文件名__Accelerated_C____Practical_Programming_by_Example.chm-> C 实用编程示例.chm
文件名__Python_Essential_Reference__2nd_Edition_.pdf-> Python Essential Reference 2nd Edition.pdf
文件名__Text_Processing_in_Python.chm-> Python.chm 中的文本处理
推荐答案
这应该有效:
ls | %{ ren $_ $(($_.name -replace '^filename_+','') -replace '_+',' ') }
扩展别名并命名所有参数,对于更冗长但可以说更易于理解的版本,以下是等效的
Expanding the aliases and naming all argument, for a more verbose but arguably more understandable version, the following is equivalent
Get-ChildItem -Path . | ForEach-Object { Rename-Item -Path $_ -NewName $(($_.Name -replace '^filename_+','') -replace '_+',' ') }
这篇关于使用 Regex/Powershell 重命名文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文