且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Powershell 批量重命名

更新时间:2022-09-24 21:31:56

先创建几个用于测试的文件

$Directory = "C:\Test"
For($i=0;$i -le 10; ++$i) {
Set-Content -Path $("$Directory\Test($i).txt") -value $i 
}

创建结果如下图:
Powershell 批量重命名

使用下面的命令把Test换成Mail

PS D:\> $Directory = "C:\Test"
PS D:\> Get-ChildItem $Directory | Rename-Item -NewName { $_.name -Replace "Test","Mail" }

结果如下图:
Powershell 批量重命名

学习链接:

http://www.computerperformance.co.uk/powershell/powershell_replace.htm
http://www.pstips.net/bulk-renaming-files.html





      本文转自cix123  51CTO博客,原文链接:http://blog.51cto.com/zhaodongwei/2064933,如需转载请自行联系原作者