1. Easy case: fixed name
Let's say we have MP3 files that begin with the artist's name such as
Freddie Hubbard - Far Away.mp3 Freddie Hubbard - D Minor Mint.mp3 ...As we have the artist's name in the folder containing the tracks, we don't need it in each individual song. And as all files start with the same text Freddie Hubbard - (notice we include the separator dash — for removal), we select all MP3s and press <F2> key (or File > Mass rename menu) and set up a search and replace transformation as in the picture:
Note we set the mass rename dialog in Match and replace part mode, we entered the part to find in What to match box and we left the Target name template box empty, so that we eliminate the string. Hit Preview button to see what this setup does: it converts Freddie Hubbard - Far Away.mp3 into Far Away.mp3. If you are happy, click on Rename button to go ahead and change the songs.
2. Medium case: variable name with fixed length
The following rename task calls again for eliminating the artist name, but see that we also have a variable number to remove (101, 102 etc)
101-eberhard_weber-touch.mp3 102-eberhard_weber-sand_glass.mp3 103-eberhard_weber-yellow_fields.mp3 ...We can't just search for a fixed text this time. However we can exploit the fact that the variable part to be removed has a fixed length (19 characters long from the beginning). So we search for the special character range token that corresponds to these letters, which is $[1:19] and again replace it with nothing:
The format of the character range token includes the starting letter (position 1), followed by a colon and then the number of characters to match (19), which explains why we used 1:19 to match the first 19 letters.
The range token supports matching the end of the string too, using negative numbers, e.g. $[-5:5] would match the last 5 characters of the filename
3. Advanced case: variable leading bit
In many cases there's no easy pattern to exploit with simple search and replace. There are many possibilities but let us consider a variable leading portion that is delimited by a separator character, e.g. a dash (-). Notice how the text to be removed doesn't have a fixed length either:
123-file1.txt abcde-file2.txt 3210-file3.txt ...To deal with this case we use a regular expression that matches everything from the beginning and up to the separator dash, which is:
^.*\-
Regular expressions aren't my forte, but they are a bit like DOS wildcards with rich syntax. In the above regexp the following special characters are used:
^ | matches the beginning of the filename | |
.* | matches any character, any number of times (wildcard) | |
\- | matches the dash; since - is a special regexp symbol we need to escape it with a backslash |
If you add all the above together, our regexp matches both the number 123- and the letters abcde-, and in general everything that comes before the dash! The mass rename dialog setup is similar, only notice we've ticked RE (regexp) box for the special search string:
Post a comment on this topic »