In that case, all you need to do is to change the condition for the kepub to what I said. That will put the kepub version where you want it when it. Which means it looks like:
Code:
program:
if 'KEPUB' in field('formats') then
return strcat("books", "/", field('authors'), field('title'))
else
return strcat(".books/", field('authors'), "-", field('series'), "-", field('series_index'), "-", field('title'), field('formats'))
fi;
But, I can't do anything about the leading dot in the directory name.