I am reorganizing my MP3 collection and found that I needed to rename a large quantity of files. Of course, there are many free utilities that allow this operation - and that can use MP3 tags in the process - but I thought that I might write one myself. Thanks to regular expressions, the task shouldn't be that hard. In fact, in a few minutes I came up with the following console application. As you see, most of the code is used to extract and validate arguments on the command line:
Imports
Module
Dim recurse As Boolean = False Dim renameMode As Boolean = False Dim oldNamePattern As String = Nothing Dim newNamePattern As String = Nothing
End
At the very minimum, the RENX utility requires two arguments: a regex that specifies which files in the current directory (and its subdirectories, if you add the /S option) must be renamed, and a second regex that specifies how to rename the files that are matched by the first regex. The power of RENX is the fact that the first regex can (actually, must) specify one or more groups of characters, and these groups are then referenced in the second regex. For example, let's suppose that I have a folder with the following files:
01 Speak to Me.mp3 02 On the Run.mp3 03 Time.mp3 04 The Great Gig in the Sky.vb3 05 Money.mp3 06 Us and Them.mp3 07 Any Colour You Like.vbr 08 Brain Damage.mp3 09 Eclipse.vb3
and that I want to rename them as follows:
01 - Speak to Me - The Dark Side of the Moon.mp3 02 - On the Run - The Dark Side of the Moon.mp3 03 - Time - The Dark Side of the Moon.mp3 04 - The Great Gig in the Sky - The Dark Side of the Moon.vbr 05 - Money - The Dark Side of the Moon.mp3 06 - Us and Them - The Dark Side of the Moon.mp3 07 - Any Colour You Like - The Dark Side of the Moon.vb3 08 - Brain Damage - The Dark Side of the Moon.mp3 09 - Eclipse - The Dark Side of the Moon.vbr
Here's the RENX command that does it:
RENX "(\d\d) (.+?)(\..+)" "${1} - ${2} - The Dark Side of the Moon.${3}"
Notice that the first regex creates three groups by enclosing them in parenthesis: (\d\d) matches the song number, (.+?) matches the song title, and (\..+) matches the file extension, dot included. The second argument can then reorder these three groups, using the ${N}, where N is the position of the group as specified in the first regex. It is therefore to insert a dash after the song number, and the albumname after the song title.
Because the RENX utility is quite dangerous, by default it doe NOT rename the files, and it just lists how files would be renamed. To actually proceed with the rename operation, you must specify the /R option:
RENX "(\d\d) (.+?)(\..+)" "${1} - ${2} - The Dark Side of the Moon${3}" /R
That's all. You can play with the source code to extend the RENX utility as you prefer, and maybe turn it into a Windows Form application, or you can download the binary version from this link: Renx.zip (5.51 KB)
Remember Me
Powered by: newtelligence dasBlog 1.8.5223.1