Avatar of redman20111
redman20111
 asked on

Rename sub-folders in multiple locations

Running Windows 2008 R2 server.

On the D drive of each server are folders named:

Marketing1
Marketing2
Marketing3
Marketing4

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
mpbeavjr

8/22/2022 - Mon
mpbeavjr

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]
redman20111

ASKER
Thanks, do you know how I would do that for

- just one sub-folder
- all of them?

Thanks a lot!
mpbeavjr

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
redman20111

ASKER
Hi

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

C:\Test1\RenameTest0010101011
C:\Test1\RenameTest92309132

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

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

ALso:

- 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?
ASKER CERTIFIED SOLUTION
mpbeavjr

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
or
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