pylab_ml.common.file_io.get_latestfile

get_latestfile(filename, logerror=None)[source]

Get the file with the latest date.

eg. If there are multiple files with the same prefix and suffix, this function will return the one with the latest date in the directory. For example, if there are files named ‘data_20210101.txt’, ‘data_20210201.txt’, and ‘data_20210301.txt’, and you call get_latestfile(‘data_*.txt’), it will return ‘data_20210301.txt’ as it has the latest date.

Parameters:
  • filename (str) – The file name with a prefix and suffix to search for. The prefix is the part of the file name before the wildcard ‘*’, and the suffix is the part of the file name after the wildcard ‘*’.

  • logerror (function, optional) – A function to log errors. If None, errors will be printed to the console. Default is None.

Returns:

The file name with the latest date, or None if no matching files are found.

Return type:

str or None