Hi everyone,

I have tons of folders to rename. I would like to know how can i create a script to rename all of them following this rule:

Name of actual folder: “AAA BBB - C D E”

I want it to look like this: “AAABBB_CDE”

How can i do it with powershell? or any other way.

tried with .bat file but wasnt working how i want it, mostly cause of special characters.

6 Spice ups

Welcome to the community. You would want to use the Rename-Item with the -replace parameter. This should get you started, but feel free to post back with questions as they arise.

2 Spice ups

Its simple you should have googled “powershell rename folder”

try in a test folder with 2 or more folder

gci C:\temp\ | Rename-Item -NewName {$_.name -replace '-', '_' -replace(' ')} 

2 Spice ups

Sorry for the late response, and btw thank you both of you. Is it possible to apply the rename-item to onedrive folder? or thats the reason this error keeps showing?

Rename.Item : The term ‘Rename.Item’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name,
or if a path was included, verify that the path is correct and try again.
At line:1 char:6

  • dir| Rename.Item -NewName {$.name -replace " - ", ""}
  • CategoryInfo : ObjectNotFound: (Rename.Item:String) , CommandNotFoundException
  • FullyQualifiedErrorId : CommandNotFoundException