setanta/ebookmaker

Wild cards are sorted as strings

Opened this issue · 0 comments

This issue affects users with more than 9 text files.

# Expand wild cards.
if item['type'] == 'text' and '*' in item['source']:
    files = sorted(glob(item['source']))

The simple sorted function sort the filenames with the wildcard as strings, which in the case where the filenames are 'file1, file2,... , file10' the sorted list ends up as 'file1, file10, file2, ..., file9'.
To fix this I used the natsort package, but I leave it up to the author to choose his prefered method to naturally sort filenames.

from natsort import natsorted

# Expand wild cards.
if item['type'] == 'text' and '*' in item['source']:
    files = natsorted(glob(item['source']))