我在这种格式的文件夹中有很多文件
constant_blah_blah_blah.png
如何使用空格替换下划线,并使用PowerShell从中删除constant_?
提前致谢。
答案 0 :(得分:6)
你可以试试这个
Get-childItem constant* | % {rename-item $_.name ($_.name -replace '_',' ')}
Get-childItem constant* | % {rename-item $_.name ($_.name -replace 'constant ','')}
答案 1 :(得分: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 '_', ' ')
}
或更短:
ls constant_* | %{rni $_ ($_.Name -replace '^constant_' -replace '_', ' ')}