Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to trim the sub-folders of my music directory . I want to remove everything behind the "(" in the folder names.


d: \ media \ folder1 (2011)

d: \ media \ folder2 (2012)

what I want to keep is:

d: \ media \ folder1

d: \ media \ folder2

can it be done with powershell?

share|improve this question

Here is one way:

Get-ChildItem D:\media | Where-Object{$_.PsIsContainer} | %{$newName = $_.Name -replace '(.+) .+', '$1'; Rename-Item $_ $newName}

There weren't a lot of details in your question, so you may need to tweak it to match your exact needs, but that should point you in the right direction.

share|improve this answer
thanks for you answer. But i'm stuck if i run the command in powershell i'm gettiting ""Name" is a ReadOnly property." what i want reach is: I have a parent directory "d:\media" with a lots of sub-folders, what all the sub-folder have in common is that they all have "(2010)" or "(2011)" etc . in the folder name. like "d:\media\gordon (2010)" i want to remove everything after the character"(" and just keep "d:\media\gordon" as the folder name. – user149391 Jul 31 '12 at 15:07
Try it with the edit. – EBGreen Aug 2 '12 at 12:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .