大规模文件重命名 - PowerShell

3

我有很多以这种格式命名的文件放在一个文件夹中

constant_blah_blah_blah.png

如何使用PowerShell将下划线替换为空格,并删除其中的constant_?

提前感谢。


抱歉,我什么都没试过。我不知道 PowerShell 怎么工作。 - Tsarl
你应该尝试在这里搜索、谷歌或查看MSDN上的Powershell文档来解决它。 - Tom H
2个回答

7
# gather all files that match the criteria
Get-ChildItem constant_* |
   ForEach-Object {
      # remove the "constant_" from the beginning and replace _ by space.
      Rename-Item $_ ($_.Name -replace '^constant_' -replace '_', ' ')
   }

更简洁地说:
ls constant_* | %{rni $_ ($_.Name -replace '^constant_' -replace '_', ' ')}

+1 用于筛选和扩展 ls / %。 - Jeroen Wiert Pluimers

6
你可以尝试这个。
Get-childItem constant* | % {rename-item $_.name ($_.name -replace '_',' ')}
Get-childItem constant* | % {rename-item $_.name ($_.name -replace 'constant ','')}

这将进行两次重命名,但这并不必要(请参见我的答案)。 - Joey

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接