import pathlib
from typing import List


def find_all_csvfiles(tiledir: pathlib.Path,
                      reverse: bool = False) -> List[pathlib.Path]:
    """ Find all the CSV files in the tile directory

    :param Path tiledir:
        The tile directory to load all the point detections from
    :param bool reverse:
        If true, reverse the track files
    :returns:
        The list of csv files to load for all tiles
    """
    csvfiles = []
    for subfile in sorted(tiledir.iterdir(), reverse=reverse):
        if subfile.suffix not in ('.csv', ):
            continue
        if not subfile.is_file():
            continue
        csvfiles.append(subfile)
    return csvfiles