Rename subfolder directories Windows 2008 R2

Just trying to work out a way to rename some sub folders and could do with some help.

Basically, When our staff write documentation for a proposal, they create a folder with the project name. When they win the proposal and it becomes a project, the copy the proposal folder into the newly created project folder (which is on a different network drive) See example below:

-Site
–Project
—B100020.01 – Project 1
—-B10020.001 – Original Proposal
—B100022.01 – Project 2
—-B10022.001 – Original Proposal

What I would like to do is systematically rename the proposal folder underneath the new project folder to _Proposal.

e.g.
-Site
–Project
—B100020.01 – Project 1
—-_Proposal
—B100022.01 – Project 2
—-_Proposal

The problem we are having is that the proposal and project folder names can be upwards of 100 characters and we are having file length issues with the server.

Now I know there are tools out there for batch renaming but I cannot find anything that will look at a certain folder level and look down to the next level and rename.

Any ideas?

Answer

To expand on my comment ‘Script it’:

PowerShell:

# Be in ...\site\project
# Get a list of all the folders (B100020.01, B100020.02, ...)
# Then go into ech of those and get a list of all the folders (B10020.001 - Original Proposal...)
# Store them in a list called $props
$props = (gci | ?{$_.psiscontainer} | gci | ?{$_.psiscontainer} )

# Now go through every folder 
# check if they have 'proposal' in the name, and if so rename them to '_proposal'
foreach ($foldr in $props) { if ($folder.Name.ToLower().Contains('proposal')) { Rename-Item -path $foldr.fullname -newname '_proposal' } }

(Warning, functionality not guaranteed, use for ideas only).

Attribution
Source : Link , Question Author : leepryor , Answer Author : TessellatingHeckler

Leave a Comment