我在目录 G:\TXT 中,我想将文件夹 TXT 中的 2 个文件名(a01mm.txt 和 a02mm.txt 更改为 a01.txt 和 a02.txt),但是不起作用。没有任何结果。谁能告诉我我做错了什么。我试过 电脑图形图像| rni -newname { $_.name -TrimEnd(2) }
PowerShell:
Get-ChildItem G:\TXT | Where-Object { $_.Name -match "a\d\dmm\.txt" } | ForEach-Object {
$newName = $_.Name -replace "mm", ""
Rename-Item -Path $_.FullName -NewName $newName
}
或
Get-ChildItem | Rename-Item -NewName { $_.Name -replace "mm", "" }
运行此PowerShell脚本后,“TXT”目录中的文件“a01mm.txt”和“a02mm.txt”应重命名为“a01.txt”和“a02.txt”。运行脚本时确保您位于正确的目录中,或者根据需要提供文件的完整路径