批量文件重命名 - PowerShell

Tsa*_*arl 3 powershell

我在这种格式的文件夹中有很多文件

constant_blah_blah_blah.png
Run Code Online (Sandbox Code Playgroud)

如何用空格替换下划线并使用PowerShell从中删除constant_?

提前致谢.

JPB*_*anc 6

你可以试试这个

Get-childItem constant* | % {rename-item $_.name ($_.name -replace '_',' ')}
Get-childItem constant* | % {rename-item $_.name ($_.name -replace 'constant ','')}
Run Code Online (Sandbox Code Playgroud)


Joe*_*oey 5

# 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 '_', ' ')
   }
Run Code Online (Sandbox Code Playgroud)

或更短:

ls constant_* | %{rni $_ ($_.Name -replace '^constant_' -replace '_', ' ')}
Run Code Online (Sandbox Code Playgroud)