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.
Windows Server 2008PowershellScripting Languages

Avatar of undefined
Last Comment

8/22/2022 - Mon

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]

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?
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy


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?

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question