I want to replace all white space characters with "_" in the names of all subfolders and files. Unfortunately, when I type:
Get-ChildItem -recurse -name | ForEach-Object { Rename-Item $_ $_.replace(" ","_") }
Error message:
Rename item: the source and destination path must be different. By line: 1 char: 60 + Get-ChildItem -recurse -name | ForEach-Object {Rename-Item <<<<$ _ $ .replace ("," ")} + CategoryInfo: WriteError: (PATH_HERE) [Rename item], IOException + FullyQualifiedErrorId: RenameItemIOError, Microsoft.PowerShell.Commands.RenameItemCommand
How should I improve this short code?
source
share