1. 程式人生 > >Powershell 批量重命名

Powershell 批量重命名

set alt cto tips val directory mark form ips

先創建幾個用於測試的文件
$Directory = "C:\Test"
For($i=0;$i -le 10; ++$i) {
Set-Content -Path $("$Directory\Test($i).txt") -value $i 
}

創建結果如下圖:
技術分享圖片

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

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

結果如下圖:
技術分享圖片

學習鏈接:

http://www.computerperformance.co.uk/powershell/powershell_replace.htm

http://www.pstips.net/bulk-renaming-files.html

Powershell 批量重命名