"Sort name"

Post any Bulk Rename Utility support requirements here. Open to all registered users.

"Sort name"

Postby bramblyBush » Thu Mar 12, 2015 9:37 pm

Is there a way to rename something like "The Beatles - Beatles For Sale - Eight Days a Week.mp3" to "Beatles, The - Beatles For Sale - Eight Days a Week.mp3"? You know, move articles like the, a, behind the main word. Like libraries sort titles. I know I can do this for every file with "the" and then the same length word after it (beatles = 7, apaches = 7 so moving it would work) but I have tons of files with different length main words.

There may be other posts about this but searching for "sort words the" isn't helpful.
bramblyBush
 
Posts: 3
Joined: Sun Feb 08, 2015 10:17 pm

Re: "Sort name"

Postby Glenn » Wed Apr 01, 2015 8:57 pm

When you have a situation where you are dealing with variable length words, the best course of action is to use wildcards, and in this case a regular expression should fit the bill. Although it would be possible to move every first word to the back before the first hyphen, it's probably safest to do these in groups e.g. All the "the"'s, then all of the "a"'s, etc.

So, in the RegEx(1) Match box put
The (.*?)( -.*)
"The " means literally match any filename starting with "The" followed by a space
(.*?) means match any series of characters - the "." means any character, the "*" means zero or more times, the "?" means don't be greedy.
This is saved as \1 (any time you surround a match sequence with parentheses, these are captured to use in the replacement and are numbered in order of appearance in the match line \1, \2, \3 ...etc.)
( -.*) means match a space followed by a hyphen followed by any series of characters, basically the rest of the line.
This is saved as \2
If we hadn't used the ? in the first grouping to turn off greediness, the first group would have matched the all the way to the last hyphen and would have made the split in the wrong place. i.e. ".*" will match the whole line first, then backtrack until the ( -.*) also matches which will be the last hyphen.

And in the Replace put
\1, The\2

That will replace all the "The"'s. To shift a leading "A", simply replace the "The" in the above with an "A".
Do the same for any other leading word you want.

Cheers,
Glenn
Glenn
 
Posts: 28
Joined: Fri Apr 14, 2006 4:53 pm
Location: Winnipeg, Canada


Return to BRU Support