Ejemplo n.º 1
0
def rename_file(file: Path, date_time: datetime,
                file_format_mode: int) -> Path:
    folder = file.parent
    stem = file.stem
    ext = file.suffix

    date_time = date_time.format("YYYY-MM-DD HH-mm-ss")

    # 1: date only
    # 2: preserve filenames
    # 3: date + old filename, do not duplicate date and remove excess whitespace
    # 4: date + old filename, do not alter old filename
    if file_format_mode is 1:
        new_filename = date_time + ext

    elif file_format_mode is 2:
        new_filename = stem + ext

    elif file_format_mode is 3:
        stem = remove_prefix(stem.strip(), date_time).strip()
        new_filename = date_time + " " + stem + ext

    elif file_format_mode is 4:
        new_filename = date_time + " " + stem + ext

    else:
        raise Exception("Filename format is invalid")

    new_file = folder.joinpath(new_filename)
    new_file = uniquify(new_file)
    file.rename(new_file)
    return file
Ejemplo n.º 2
0
def make_path(root: Path, date_time: datetime) -> Path:
    directory_schema = date_time.format("YYYY-MM")
    return root.joinpath(directory_schema)