Created
June 10, 2023 11:18
-
-
Save wences-dc-uba-ar/b7cfd592f0ae3606a869246a9baa1b4d to your computer and use it in GitHub Desktop.
Android DCIM sorter script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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