Link to home
Start Free TrialLog in
Avatar of redman20111

asked on

Rename sub-folders in multiple locations

Running Windows 2008 R2 server.

On the D drive of each server are folders named:


and so on...

Within each folder is a sub folder named "MarketingData-xxxx", for instance "MarketingData-100002" or "MarketingData-199999"

I want to rename each of this folder from "MarketingData-XXX" to "Marketing_old"

Rather than going into each folder and manually renaming, is there a Powershell I can run?

I don't mind going to the location of each top level folder (Marketing1, Marketing2 etc), seperately, but it's the renaming I find time consuming.
Avatar of mpbeavjr
Flag of United States of America image

You can use the rename-item cmdlet in powershell

You could exclude specifically all of the root level Marketing folders and simply rename any sub-folder containing "MarketingData-XXX" to "MarketingXXX_old" using a wildcard like [Marketing]
Avatar of redman20111


Thanks, do you know how I would do that for

- just one sub-folder
- all of them?

Thanks a lot!
Make sure you change your execution policy first in PowerShell

PS  C:\> Set-ExecutionPolicy RemoteSigned
Press Y to accept

To rename a single sub-folder build your powershell script like this:

Assuming folders are on the root of C: and root folder name is Test and sub-folder name is "RenameTest01" enter full path followed by new name (space in between)

Rename-Item -path C:\Test\RenameTest01 -newname RenameTest_old

Regarding the multiple sub folder renames, how many subfolders are you trying to do and are the numbers following the word "Marketing" sequential?

I could probably do it like this and manually change the path

Rename-Item -path C:\Test\RenameTest01 -newname RenameTest_old

The only thing is, the path could be


Is it possible/ recommended to use a wilcard there, e.g.

Rename-Item -path C:\Test\RenameTest* -newname RenameTest_old


- That will only rename the folder named RenameTest* within C:\Test correct?
- Can I run this from C:\ or does it have to be run from a particular location?
Avatar of mpbeavjr
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial