概要
旅行や日常の写真をフォルダ単位で管理するのが煩雑なので、 Exifの撮影日をもとに整理するPythonスクリプトを作成した。
コード概要
```python from pathlib import Path from PIL import Image from datetime import datetime
for img_path in Path("photos").glob("*.jpg"): exif = Image.open(img_path)._getexif() date = exif.get(36867) if date: folder = datetime.strptime(date, "%Y:%m:%d %H:%M:%S").strftime("%Y-%m-%d") Path(f"sorted/{folder}").mkdir(parents=True, exist_ok=True) img_path.rename(Path(f"sorted/{folder}/{img_path.name}")) ```
今後の改善
- 重複ファイルの検出機能追加
- RAWデータにも対応予定
#Python#写真管理#自動化