#1 2009-04-28 02:29

kitsune
Member
Registered: 2009-04-28
Posts: 1

How to rename files & folders by change first & last name order

Hi

I've a huge chunk of ebooks that I'm renaming
They are currently in the order of 'First Name' 'Last Name' - 'Title'

for e.g. Jane Austen - Sense and Sensibility
I'll like to switch to the 'Last Name', 'First Name' - 'Title' order: Austen, Jane - Sense and Sensibility

I've been using the
Expression: (.*) (.*) - (.*)
Replace: $2, $1 -  $3
which works fine.

However I also have chunks of books like "Harlan Ellison & Ben Bova - 01 - Brillo.pdf"
which I would like to change to "Ellison, Harlan & Bova,  Ben - 01 - Brillo.pdf"

I found
Expression: (\w+)\s(\w+)\s?(\((\d+)\))?
Replace: $2, $1 $3
posted by prologician as a solution to someone else's problem. It would work for me too if there is anyway of making the renamer ignore whatever that comes after the "-".

Any help or ideas will be greatly appreciated. Thanks

Offline

#2 2009-04-28 03:43

prologician
Member
Registered: 2009-01-30
Posts: 84

Re: How to rename files & folders by change first & last name order

I don't know where exactly to start.... I'm honored I got referenced. :3 (I was also confused as to why that regular expression is behaving the way it is, but I got that ironed out...)

For those wondering, the thread where this came from was this one.

<Fiddles with ReNamer for several minutes>

Alrighty. Here's something that might do the trick for you:

Expression: (\w+)\s(\w+)\s(\W)?
Replace: $2, $1 $3

This regular expression matches the pattern of the form "word, space, word, space, non-letter". Once it finds such a pattern (like, from your example, "Harlan Ellison &" or "Ben Bova -"), it'll swap the first two words and stick a comma between. This'll work, as long as the "title" part doesn't contain anything besides letters and numbers (and underscore).

Offline

#3 2009-04-28 10:25

krtek
Senior Member
From: Łódź (Poland)
Registered: 2008-02-21
Posts: 262

Re: How to rename files & folders by change first & last name order

Your expression is a bit not that, prologician, it will be applied to the title as well (if it will be at least two words long).
I prefer to avoid multiple searches in the filename. So let's try to make regex to match only once for given filename.

If it is always like that "first author & second author - number - title"
the best solution would be:

Expression: "(\w+)\s(\w+)\s?&\s?(\w+)\s(\w+)\s?-\s?(\d+)"
Replace: "$2, $1 & $4, $3 - $5"


Regular Expressions are not as hard to understand as you may think. Check ReNamer's manual or nice Regular Expressions tutorial for more info and start to use full power of applications that use them (like ReNamer, Mp3Tag and so on).

Offline

#4 2009-04-28 17:50

prologician
Member
Registered: 2009-01-30
Posts: 84

Re: How to rename files & folders by change first & last name order

Ah, yeah, so it does.... heh. <Makes a few tweaks>

I think the usefulness which kitsune is going for, here, is to be able to adjust any number of names at the same time, and not need to cater an entire regular expression for handling one case at a time. (If I'm reading too much into your post, kitsune, sorry about that~)

Alright, here's a revised thingy, which handles several cases better:

Expression: ([-a-zA-Z]+)\s([-a-zA-Z]+)(\s\W\s|,\s)
Replace: $2, $1$3

(Yes, there is no space between the $1 and $3). This should handle cases properly of long title names, and also cases of multiple authors, whose surnames may be hyphenated. The same issue as before, with nonletters in the title name, can still break this, though.

Original: Harlan Ellison-Watson & Ben Bova - 01 - Brillo Billy and the News.pdf
After: Ellison-Watson, Harlan & Bova, Ben - 01 - Brillo Billy and the News.pdf

Offline

Board footer

Powered by FluxBB