Skip to content

Instantly share code, notes, and snippets.

@danielsuo
Created August 17, 2023 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielsuo/67c88b8ab976c845f7e866f76c53ed16 to your computer and use it in GitHub Desktop.
Save danielsuo/67c88b8ab976c845f7e866f76c53ed16 to your computer and use it in GitHub Desktop.
photo dump
#!/usr/bin/env bash
if [ "$#" -ne 2 ]; then
echo "Usage: photo_dump.sh [SRC] [DST]"
fi
find $(realpath $1) -type f | grep -iE "(CR3|ARW|DNG|RAF|HEIC|JPG|JPEG|MOV|MP4)$" | while read SRC
do
DATE=`exiftool "$SRC" | grep "Create Date" | head -n 1 | tr -s " " | cut -d " " -f 4`
YEAR=`echo $DATE | cut -d ":" -f 1`
MONTH=`echo $DATE | cut -d ":" -f 2`
DAY=`echo $DATE | cut -d ":" -f 3`
FILENAME=$(basename "$SRC")
DST=$(realpath $2)/Photos/$YEAR/$MONTH/$DAY
if [[ "$FILENAME" == *.mov || "$FILENAME" == *.MOV || "$FILENAME" == *.mp4 || "$FILENAME" == *.MP4 ]]; then
DST=$(realpath $2)/Videos/$YEAR/$MONTH/$DAY
fi
mkdir -p "$DST"
mv "$SRC" "$DST/$FILENAME"
echo "Moved from $SRC to $DST/$FILENAME"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment