I want to replace all space characters into \"_\" in names of all subfolders and files. Unfortunately when I type:
Get-ChildItem -recurse -name | ForEach-Obj
The issue here is that if there is no space in the file name the name does not change. This is not supported by Rename-Item
. You should use Move-Item
instead:
Get-ChildItem -recurse -name | ForEach-Object { Move-Item $_ $_.replace(" ", "_") }
Additionally, in your answer you missed the underscore in $_.replace(...)
plus you where replacing spaces with an empty string. Included this in my answer.