#1 2026-03-06 01:30

Digidoc
Member
Registered: 2026-03-06
Posts: 6

Renaming ebook files

Greets and hello. I have many thousands of ebooks which need to be renamed. They are actually in this format:

A Change in Altitude - Anita Shreve.mobi
A Wedding in December_ A Novel - Anita Shreve.mobi
Fortune's rocks_ a novel - Anita Shreve.mobi
Gentlemen prefer blondes - Anita Loos.mobi
The Red Tent - Anita Diamant.mobi

Or: Title - Author First, {sometimes initials} Author Last.

I want to rename to this:

Shreve, Anita-A Change In Altitude.mobi
Shreve, Anita-A Wedding In December_A Novel.mobi
Shreve, Anita-Fortune's Rocks_A Novel.mobi
Loos, Anita-Gentlemen Prefer Blondes.mobi
Diamant, Anita-The Red Tent.mobi

Or: Author Last, Author First-Title.
----------------
I can capitalize each word.
I can change [ - ] to a single [-]
I can replace [_ ] to a single [-]
Is it possible to analyze the title, and rearrange as I have suggested? I have another 14,000 books to rename, so even if I can manage 1000 per month, this will take me a --very-- long time. Thoughts? Suggestions? (email is always welcome)

Perhaps each space in the original name could be a split point?
These split points could then be assigned numbers?
The name could then be arranged to put the last split first, followed by a comma, the second to last split point, followed by a [-] and then the remainder of the split points?

Last edited by Digidoc (2026-03-06 02:25)

Offline

#2 2026-03-06 17:54

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,521

Re: Renaming ebook files

You'll need the power of the Regular Expressions rule for this one.

Replace expression "^(.*)\s+-\s+(\S+)\s+(\S+)$" with "$3, $2-$1" (skip extension).

Note that this pattern assumes that the author name consists of exactly two words, no more, no less.

Offline

#3 2026-03-06 19:00

eR@SeR
Senior Member
Registered: 2008-01-23
Posts: 359

Re: Renaming ebook files

Hello,

This RegEx rule include cases if there are 2, 3 or more words (initials as well) in author's name:

Replace expression "(.+) - ([^\s]+) (.+)" with "$3, $2-$1" (skip extension)

From:

A Change in Altitude - Anita Shreve.mobi
A Wedding in December_ A Novel - Anita Shreve.mobi
Fortune's rocks_ a novel - Anita Shreve.mobi
Gentlemen prefer blondes - Anita Loos.mobi
The Red Tent - Anita Diamant.mobi
The Hobbit and The Lord of the Rings - J.R.R. Tolkien.mobi
Extinction - Douglas J. Preston.mobi
One Hundred Years of Solitude - Gabriel García Márquez.mobi
Game of Thrones - George Raymond Richard Martin

To:

Shreve, Anita-A Change in Altitude.mobi
Shreve, Anita-A Wedding in December_ A Novel.mobi
Shreve, Anita-Fortune's rocks_ a novel.mobi
Loos, Anita-Gentlemen prefer blondes.mobi
Diamant, Anita-The Red Tent.mobi
Tolkien, J.R.R.-The Hobbit and The Lord of the Rings.mobi
J. Preston, Douglas-Extinction.mobi
García Márquez, Gabriel-One Hundred Years of Solitude.mobi
Raymond Richard Martin, George-Game of Thrones

Addition: If you want to have Author Last, Author First {sometimes 2+ words, initials} as a result use:

Replace expression "(.+) - (.+) (.+)" with "$3, $2-$1" (skip extension)

Offline

#4 2026-03-07 11:20

Digidoc
Member
Registered: 2026-03-06
Posts: 6

Re: Renaming ebook files

Wow, this works great. This will save me hundreds of hours automating my naming process. I used it on a folder containing 94 books. The only ones who messed up were: 2001 A Space Odyssey - Arthur C. Clark; it came out as C Clark, Arthur-2001 A Space Odyssey.

I think this has to do with the initials containing [.] or not.

Offline

#5 2026-03-07 19:58

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,521

Re: Renaming ebook files

You can handle it with a second rule to rearrange 2-token and 3-token authors separately:

1) Replace expression "^(.*)\s+-\s+(\S+)\s+(\S+)$" with "$3, $2-$1" (skip extension)
2) Replace expression "^(.*)\s+-\s+(\S+)\s+(\S+)\s+(\S+)$" with "$3 $4, $2-$1" (skip extension)

This works on spaces and non-space sequences, so dots don't be a problem.

Rearrange the replacement pattern "$3 $4, $2-$1" to get "C. Clark, Arthur" in a different order.

Input:

Shreve, Anita-A Change in Altitude.mobi
Shreve, Anita-A Wedding in December_ A Novel.mobi
Shreve, Anita-Fortune's rocks_ a novel.mobi
Loos, Anita-Gentlemen prefer blondes.mobi
Diamant, Anita-The Red Tent.mobi
C. Clark, Arthur-2001 A Space Odyssey.mobi

Output:

Shreve, Anita-A Change in Altitude.mobi
Shreve, Anita-A Wedding in December_ A Novel.mobi
Shreve, Anita-Fortune's rocks_ a novel.mobi
Loos, Anita-Gentlemen prefer blondes.mobi
Diamant, Anita-The Red Tent.mobi
Clark C., Arthur-2001 A Space Odyssey.mobi

Offline

#6 Yesterday 15:09

Digidoc
Member
Registered: 2026-03-06
Posts: 6

Re: Renaming ebook files

Thanks, we are almost there. With these 2 rules:
^(.*)\s+-\s+(\S+)\s+(\S+)\s+(\S+)$ WITH $3 $4, $2-$1
^(.*)\s+-\s+(\S+)\s+(\S+)$ WITH $3, $2-$1

Original file is: Unsuspecting Mage, The - Brian S. Pratt

I get: S. Pratt, Brian-Unsuspecting Mage, The.epub

I want to get: Pratt, Brian S.-Unsuspecting Mage.epub

The trick is in the author. Sometimes the author only has first and last name (this works great). But if the name has initials, it can be 1 or 2 (or more). Sometimes there are only initials. These initials should go after the last name and not before.

My next batch contains 345 books. When testing these rules, all but 22 rename correctly. The ones which do not work put the initials before and not after the last name. I get the following:
J. Daniels, B.-A Woman With A Mystery.epub
J. Daniels, B.-Ambushed!.epub
J. Daniels, B.-Big Sky Standoff.epub
J. Daniels, B.-Cowboy Accomplice.epub
J. Daniels, B.-Day Of Reckoning.epub
J. Daniels, B.-Intimate Secrets.epub
J. Daniels, B.-Keeping Christmas.epub
J. Daniels, B.-Love At First Sight.epub
J. Daniels, B.-Mountain Sheriff.epub
J. Daniels, B.-Mystery Bride.epub
J. Daniels, B.-Premeditated Marriage.epub
J. Daniels, B.-Secret Weapon Spouse.epub
J. Daniels, B.-The Agent's Secret Child.epub
J. Daniels, B.-The Cowgirl In Question.epub
J. Daniels, B.-The Masked Man.epub
J. Daniels, B.-Wanted Woman.epub
J. Daniels, B.-When Twilight Comes.epub
K. Evenson, B.-Dead Space_Martyr.epub
K. Martin, Bradley-Under The Loving Care Of The Fatherly Leader_North Korea And The Kim Dynasty.epub
L. Newport, B.-Reapers, Inc.- Brigit's Cross.epub
S. Pratt, Brian-Shades Of The Past_Book Six Of The Morc.epub
S. Pratt, Brian-The Mists Of Sorrow_Book Seven Of The M.epub
S. Pratt, Brian-The Star Of Morcyth_Book Five Of The Mo.epub
S. Pratt, Brian-Trail Of The Gods_The Morcyth Saga Book.epub
T. Washington, Booker-Works Of Booker T. Washington.epub
V. Larson, B.-Mech.epub

I am happy to supply sample files if anyone sends email requesting them.

Last edited by Digidoc (Yesterday 17:39)

Offline

#7 Yesterday 19:51

Digidoc
Member
Registered: 2026-03-06
Posts: 6

Re: Renaming ebook files

For my next rename batch, I have 100 folders. These contain 247 .epub books (named incorrectly). I move all those to a work folder, and delete the 100 original folders containing many unwanted files. I then use the free program Hamster to convert from .mobi to .epub (this is the format used in Kindle). Hamster could not handle 2 books as the names were too long. This conversion takes about 15-20 minutes. Once converted, I use Renamer; all are correct except those containing initials. I also found that if the name is 3 words, it does not work correctly either.

Offline

Board footer

Powered by FluxBB