Get-ChildItem -Filter "*.txt" -Recurse | ForEach-Object {
$newname = $_.Name -replace "AAA", ""
Rename-Item $_.FullName $newname
}
在指定目录,按shift加鼠标右键打开PowerShell,复制这段代码进去,会将该目录以及该目录子目录中的txt文件名中包含“AAA”的替换为空,比如之前是“AAA_1.txt”会变为“_1.txt”
如果只想替换当前目录中的文件,不想替换子目录中的文件,则使用下面这段代码
Get-ChildItem -Filter "*.txt" -File | ForEach-Object {
$newname = $_.Name -replace "AAA", ""
Rename-Item $_.FullName $newname
}
区别就是将“Recurse”改为“File”
此外软件Everything
有批量修改名字的功能,如果文件不在同一个文件夹可以考虑使用
网友评论