Quantcast
Channel: MobileRead Forums - Calibre
Viewing all articles
Browse latest Browse all 31494

Need help on a Save to Disk template

$
0
0
I'm trying to come up with a Save-To-Disk template to allow me to export my books. I've figured out some of what I need to do, but I'm stuck on the final piece. Specifically, I need to remove the extra underscores that get generated from the template when a book has no subseries and/or series.

I have the following custom columns:

Division (Major classification for sorting libraries)
Genre (Fiction, Reference, Science Fiction, etc)
AuthorLookup (For dealing with multiple authors, etc)
Subseries (A series-like field used when there's more than 1 level to the series information. If a book has a subseries, it will always have a series as well)

Currently, my template looks like this:

Code:

{#division}/{#genre}/{#authorlookup}/{series}/{series_index:0>3s}_{#subseries}{#subseries_index:0>3s}_{title}
In plain English, I always want the Division, Genre, and AuthorLookup as nested folders. Inside the AuthorLookup, I want just the book title if there's no series. If there's a series, I want another subfolder for the series, with each book in the series starting with its index (padded to 3 chars) followed by an underscore. After that, if there's a subseries I want the subseries name and index (padded to 3 chars) followed by another underscore. Finally, I want the book title.

Some examples of what I want:

Code:

Other/Fiction/Smith_John/Just Some Book.epub
Other/Fiction/Smith_John/Some Books/001_A Book.epub
Other/Fiction/Smith_John/Some Books/002_Another Book.epub
Other/Fiction/Smith_John/Lots of Books/001_FirstSet001_This Is a Book.epub
Other/Fiction/Smith_John/Lots of Books/002_FirstSet002_This Is Also a Book.epub
Other/Fiction/Smith_John/Lots of Books/003_SecondSet001_First Book of the Second Set.epub
Other/Fiction/Smith_John/Lots of Books/004_SecondSet002_Second Book of the Second Set.epub

If I just use the template above, I get:

Code:

Other/Fiction/Smith_John/__Just Some Book.epub
Other/Fiction/Smith_John/Some Books/001__A Book.epub
Other/Fiction/Smith_John/Some Books/002__Another Book.epub
Other/Fiction/Smith_John/Lots of Books/001_FirstSet001_This Is a Book.epub
Other/Fiction/Smith_John/Lots of Books/002_FirstSet002_This Is Also a Book.epub
Other/Fiction/Smith_John/Lots of Books/003_SecondSet001_First Book of the Second Set.epub
Other/Fiction/Smith_John/Lots of Books/004_SecondSet002_Second Book of the Second Set.epub

As you can see, in cases where there's no series, I get 2 underscores in front of the book title (I think one of these is converted from an empty folder name).
In cases where there's a series but no subseries, I get 2 underscores instead of 1 between the series index and the book title.

I've figured out prefixes and suffixes, and they help some, but I can't use them with padded indices (I get an error when trying to Apply). So how do I strip out the extra underscores when there's no subseries (or series)?

Viewing all articles
Browse latest Browse all 31494

Trending Articles