I recently started using powershell, cause i find it very usefull and powerfull 🙂
So this is the scenario :
Customer have a folder structure that used to have commas in it.
Because of their latest program addition, this fails, due to the commas.
Essentially, they just want to replace the commas with for example ” – “
This is what i have.. And it works, but i feel it’s inefficient.
The script does what it’s supposed to, but as soon as one path is changed, the remaining will fail because the original path have been changed, you follow me? 🙂
$folderpath = "C:\pathcontainingcomma"
foreach ($i in get-childitem $folderpath -Recurse) {
$name = $i.name.replace(","," - ")
Rename-Item -Path $i.fullname -NewName $name -Force -Verbose
}
i hope i explained well enough, please ask questions if you have any 🙂
You would need to rename from the inside out to avoid changing paths you still need to process, so I guess the following should work: