def find_latest_file(top: str, pattern: Pattern) -> str:
    """Find latest file matching a pattern in each directory.

    Find latest file defined by a file pattern and natural sort
    for each directory and sub directory a file pattern match
    occurs.

    Parameters
    ----------
    top : base directory path
    pattern : regular expression to match file name pattern

    Yields
    ------
    full file paths matching pattern.

    """

    for root, dirs, files in os.walk(top):
        try:
            file_name = max(match_files(files, pattern), key=alphanum_key)

            yield os.path.join(root, file_name)
        except ValueError:
            pass
def find_latest_file ( top : str , pattern : Pattern ) -> str : for root , dirs , files in os . walk ( top ) : try : file_name = max ( match_files ( files , pattern ) , key = alphanum_key ) yield os . path . join ( root , file_name ) except ValueError : pass
Find latest file matching a pattern in each directory.

    Find latest file defined by a file pattern and natural sort
    for each directory and sub directory a file pattern match
    occurs.

    Parameters
    ----------
    top : base directory path
    pattern : regular expression to match file name pattern

    Yields
    ------
    full file paths matching pattern.