跳转至

富士RAF重命名

1. 下载ExifTool

官网:ExifTool by Phil Harvey

下载 Windows Executable 版本,解压即可得到exiftool(-k).exe

命令行使用1

exiftool(-k).exe $FILE_PATH$

2. 读取拍摄日期

使用os.popen()读取.RAF文件信息:

terminal_message = os.popen(rf'.\exiftool.exe {raf_path}').read()

3. 批量重命名脚本

import os
from concurrent.futures import ThreadPoolExecutor
from concurrent.futures import as_completed

import tqdm

from koko_learn._base import ENV


def __run(file, path_src, path_dst, aim_model):
    raf_path = os.path.abspath(f'{path_src}/{file}')
    if aim_model:
        cmd = (f'{ENV.PATH_EXIFTOOL} '
               f'"-Model={aim_model}" '
               f'"-FileName<CreateDate" -d "{path_dst}/%Y%m%d/%Y%m%d_%%f.%%e" '
               f'"{raf_path}"')
    else:
        cmd = (f'{ENV.PATH_EXIFTOOL} '
               f'"-FileName<CreateDate" -d "{path_dst}/%Y%m%d/%Y%m%d_%%f.%%e" '
               f'"{raf_path}"')
    os.popen(cmd)


def raf_renamer(path_src: str,
                path_dst: str,
                aim_model: str,
                max_workers: int = ENV.MAX_WORKERS
                ) -> None:
    """RAF文件重命名和归档

    Parameters
    ----------
    path_src : str
        源路径
    path_dst : str
        目标路径
    aim_model : str
        目标相机型号
    max_workers : int
        最大工作线程,默认12

    Returns
    -------
    None

    """
    assert os.path.exists(ENV.PATH_EXIFTOOL), 'exiftool.exe is not found'

    if not os.path.exists(path_dst):
        os.mkdir(path_dst)

    files = os.listdir(path_src)
    t_file_list = tqdm.tqdm(files)

    with ThreadPoolExecutor(max_workers=max_workers) as t:
        futures = [t.submit(__run, file, path_src, path_dst, aim_model) for file in files if file != 'Desktop.ini']
        for future in as_completed(futures):
            t_file_list.update(1)
            t_file_list.set_description(future.result())


if __name__ == '__main__':
    src = r'C:\Users\Artmallo\Desktop\xxx'
    dst = r'C:\Users\Artmallo\Desktop\test'
    raf_renamer(src, dst, aim_model='X-T50')

  1. 知乎,@周德蔚,读取RAW图像的metadata