How can I reorganize photo folders by capture date and keep XMP sidecar files?

Asked 9/15/2021

4 views

2 answers

0

I want to change an existing photo library from event-based folders to a date-based structure such as yyyy/mm/dd/filename.ext, while preserving the XMP sidecar files that contain edits and metadata. My current camera-import workflow already saves new files by date, but I need a way to reorganize older images already on disk. Is there a simple way to move both the image files and their matching .xmp sidecars into date-based folders using the images' capture metadata?

Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0

Photography Stack Exchange contributor

4y ago

2 Answers

1

Here's the shell script I came up with:

#!/bin/bash

set -e

in_dir=$1

for f in $(find $in_dir -iname \*.cr2 -or -iname \*.jpg | sort); do
  out_dir=$(exiftool -DateTimeOriginal $f | awk '{print $4}' | sed 's#:#/#g')
  mkdir -p $out_dir
  mv -v $f $out_dir/$(basename $f)
  mv -v $f.xmp $out_dir/$(basename $f).xmp || true
done

rmdir $in_dir

It's invoked one directory at a time, and will crash if it encounters anything unusual. It also doesn't work if there are spaces in any filename. So it's not great, but it solves my problem for now... better answers are still welcome, if not for me, then for the next person who comes along.

Originally by user101785. Source · Licensed CC BY-SA 4.0

user101785

4y ago

0

AI Answer

Generated from our catalog & community — verify before relying on it.

A practical way is to batch-move the files based on each image’s EXIF capture date, then move the matching .xmp sidecar with the same basename. The community solution uses exiftool to read DateTimeOriginal, creates a YYYY/MM/DD folder, moves the photo there, and then moves filename.ext.xmp alongside it.

In short, the workflow is:

  1. Read each photo’s capture date from EXIF metadata.
  2. Create the corresponding yyyy/mm/dd destination folder.
  3. Move the photo.
  4. Move its matching sidecar file too.

This solves the main issue because sidecars are preserved as files on disk rather than regenerated. The posted shell script works for .cr2 and .jpg, but it is basic: it can break on unusual files or filenames with spaces, so test on a copy first and improve quoting if needed.

If your edits are stored in XMP sidecars, keeping each sidecar with its original image basename is the key requirement.

UniqueBot

AI

4y ago

Your Answer