def sorted_files(globber, num_sort=True, num_indices=None, return_num=False):
files = glob.glob(globber)<EOL>files.sort()<EOL>if not num_sort:<EOL><INDENT>return files<EOL><DEDENT>num_indices = num_indices or np.s_[:]<EOL>allfiles = []<EOL>for fn in files:<EOL><INDENT>nums = re.findall(r'<STR_LIT>', fn)<EOL>data = [int(n) for n in nums[num_indices]] + [fn]<EOL>allfiles.append(data)<EOL><DEDENT>allfiles = sorted(allfiles)<EOL>if return_num:<EOL><INDENT>return allfiles<EOL><DEDENT>return [f[-<NUM_LIT:1>] for f in allfiles]<EOL>
Give a globbing expression of files to find. They will be sorted upon return.
This function is most useful when sorting does not provide numerical order,
e.g.:
    9 -> 12 returned as 10 11 12 9 by string sort

In this case use num_sort=True, and it will be sorted by numbers whose index
is given by num_indices (possibly None for all numbers) then by string.