Renaming MP3 Files with Powershell


I recently bought ZZ Tops album “Rancho Texicano, The Very Best of ZZ Top” from Amazon. When I downloaded the album it had the Track number preceding the song name. Like this:
20 – I’m Bad, I’m Nationwide (Remastered).mp3
I prefer that the track numbers not be part of the file name, so I wrote this little script to strip the track number from the file name.

$dir = Get-ChildItem "C:\MUSIC\Rancho Texicano The Very Best of ZZ Top" -include *.mp3 -recurse
 foreach($x in $dir)
 { $FileName = $x.name
 $N = $FileName.tostring()
 $E = $N.split("-")
 $F = $E[1]
 $newname = $F.Trim()
 Rename-Item $x $newname
 }

It worked so fast I thought I had made an error, and now my ZZ Top songs appear in alphabetical order.
Two problems with this:

1. The song Bar-B-Que.mp3 came out Bar with no extension. So be careful.

2. My original script left a leading space in the name of each song.  I fixed that by adding the trim function: $newname = $F.trim()

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s