file_name#
- mediautils.file_name.file_name_to_datetime(path: str | PathLike) datetime[source]#
Extract a datetime from a file path based on its name.
- Parameters:
path (str | os.PathLike) – Path to a file whose stem starts with
YYYYMMDD_HHMMSS.- Return type:
datetime
- Raises:
ValueError – If the file name does not match the expected format.
Examples
>>> file_name_to_datetime("20240131_181253_blabla.jpg") datetime.datetime(2024, 1, 31, 18, 12, 53)
>>> file_name_to_datetime("some/dir/20250101_120000.png") datetime.datetime(2025, 1, 1, 12, 0)
- mediautils.file_name.replace_datetime_prefix(path: str | PathLike, dt: datetime) str[source]#
Replace the
YYYYMMDD_HHMMSSprefix of a file’s name with dt.- Parameters:
path (str | os.PathLike) – Path to a file whose name starts with
YYYYMMDD_HHMMSS.dt (datetime) – The datetime to encode as the new prefix.
- Returns:
The corrected file name (not a path).
- Return type:
- Raises:
ValueError – If the file name does not match the expected format.
Examples
>>> replace_datetime_prefix( ... "20240131_181253_blabla.jpg", datetime(2024, 1, 31, 18, 27, 53) ... ) '20240131_182753_blabla.jpg'
>>> replace_datetime_prefix( ... "some/dir/20250101_120000.png", datetime(2025, 1, 1, 11, 45, 0) ... ) '20250101_114500.png'
- mediautils.file_name.wa_file_name_to_date(path: str | PathLike) date[source]#
Extract a date from a WhatsApp file path based on its name.
- Parameters:
path (str | os.PathLike) – Path to a file matching
IMG-YYYYMMDD-...orVID-YYYYMMDD-....- Return type:
date
- Raises:
ValueError – If the file name does not match the expected WhatsApp format.
Examples
>>> wa_file_name_to_date("IMG-20251014-WA0010.jpg") datetime.date(2025, 10, 14)
>>> wa_file_name_to_date("some/dir/VID-20251027-WA0001.mp4") datetime.date(2025, 10, 27)