q789321 发表于 2018-9-1 11:23:26

Powershell 批量重命名

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

$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


页: [1]
查看完整版本: Powershell 批量重命名