我在一个文件夹里有很多这样格式的文件
constant_blah_blah_blah.png
我如何用空格替换下划线,并使用PowerShell删除常量_ ?
# 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 '_', ' ')}
你可以试试这个
Get-childItem constant* | % {rename-item $_.name ($_.name -replace '_',' ')}
Get-childItem constant* | % {rename-item $_.name ($_.name -replace 'constant ','')}