get_filename

Collocations.get_filename(times, template=None, fill=None)

Generate the full path and name of a file for a time period

Use parse_filename() if you want retrieve information from the filename instead.

Parameters
  • times – Either a tuple of two datetime objects representing start and end time or simply one datetime object (for discrete files).

  • template – A string with format placeholders such as {year} or {day}. If not given, the template in FileSet.path is used.

  • fill – A dictionary with fillings for user-defined placeholder.

Returns

A string containing the full path and name of the file.

Example:

fileset.get_filename(
    datetime(2016, 1, 1),
    "{year2}/{month}/{day}.dat",
)
# Returns "16/01/01.dat"

fileset.get_filename(
    ("2016-01-01", "2016-12-31"),
    "{year}{month}{day}-{end_year}{end_month}{end_day}.dat",
)
# Returns "20160101-20161231.dat"