That made a lot of sense, thanks Chaley!
Here's how I worked around the problem, if anyone needs to do this or something similar.
I used chaley's second suggestion for the template in General Program Mode:
Code:
program:
ta = strcat(field('title'), ' - ', field('authors'));
str_in_list(
field('tags'),
',',
'Fiction',
strcat('Fiction/', ta),
strcat('Non-Fiction/', ta))
I then created two custom columns, hidden from the main interface, but used in the template:
1st column:
Lookup name: firstauth
Column Heading: First Author
Type: Built from other columns
Template:
Code:
{authors:sublist(0, 1, & )}
2nd column:
Lookup name: serind
Column Heading: Series Index
Type: Built from other columns
Template:
Code:
{series_index:0>5.2f}
finally, I replaced the first line of the program with:
Code:
ta = test(field('series'),strcat(field('series'),'/',field('#serind'),' - ',field('#firstauth'), ' - ',field('title')), strcat(field('#firstauth'),' - ',field('title')));
Now here's what the entire program does:
1- checks if the book has a series, if yes, go to step 2, if not, go to step 4
2- if there is a series, it puts the book in a subfolder with the series name, the subfolder is inside Fiction or Non-Fiction depending on the tags.
3- name the file by using a five-digit number with leading zeroes, a decimal point, and 2 decimal places for the series index, then add a dash, the name of the first author, another dash, then the book title. End program!
4- if no series, the file goes into the main folder (fiction or non-fiction depending on the tags)
5- the file name is now simply the first author's name, a dash, and the book title. End Program!
Hope this help anyone who wants to do a similar thing in calibre. And thanks again chaley for the great insights into the inner workings of Calibre