Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wences-dc-uba-ar/b7cfd592f0ae3606a869246a9baa1b4d to your computer and use it in GitHub Desktop.
Save wences-dc-uba-ar/b7cfd592f0ae3606a869246a9baa1b4d to your computer and use it in GitHub Desktop.
Android DCIM sorter script
#!/system/bin/sh
# source: https://android.stackexchange.com/questions/215124/how-to-organize-photos-from-camera-folder-in-to-folders-sorted-by-month-names
set -e
DIR='/sdcard/DCIM/100ANDRO'
find $DIR -maxdepth 1 -type f -iname '*.jp*g' -o -iname '*.png' |
while read -r photo
do
month=$(exiv2 -q pr "$photo" | busybox awk -v c=1 -F '[: ]' '/timestamp.*[0-9]{4}:[0-9]{2}:[0-9]{2}/{print $5"_"$6; c=0} END{exit c}') ||
month=$(busybox stat -c %y "$photo" | busybox awk -v c=1 -F '[- ]' '/[0-9]{4}-[0-9]{2}-[0-9]{2}/{print $1"_"$2; c=0} END{exit c}') ||
{ echo "Couldn't find month for $photo" >&2; continue; }
mkdir -p "$DIR/$month"
mv -n "$photo" "$DIR/$month/"
done
echo Done.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment