-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpath_utils.py
More file actions
29 lines (24 loc) · 938 Bytes
/
path_utils.py
File metadata and controls
29 lines (24 loc) · 938 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""
path_utils.py
Utility functions for handling and validating file system paths.
"""
import os
def construct_dest_path(src_path, dest_dir, date_taken):
"""
Construct the destination file path based on the source file path,
destination directory, and the date the file was taken.
Args:
src_path (str): The source file path.
dest_dir (str): The destination directory.
date_taken (datetime): The date the file was taken.
Returns:
str: The constructed destination file path.
"""
parent_folder = os.path.basename(os.path.dirname(src_path))
base_name, ext = os.path.splitext(os.path.basename(src_path))
year = str(date_taken.year)
month = f"{date_taken.month:02d}"
day = f"{date_taken.day:02d}"
dest_folder = os.path.join(dest_dir, year, month, day)
dest_filename = f"{parent_folder}_{base_name}{ext}"
return os.path.join(dest_folder, dest_filename)