Last active
August 29, 2015 13:58
-
-
Save iomz/10022986 to your computer and use it in GitHub Desktop.
Rename photos in the specified directory like Dropbox's "Camera Upload" based on last modified dates
This file contains hidden or 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
#!/bin/sh | |
ABSPATH=$(cd "$1"; pwd) | |
COUNT=0 | |
if [ ! -e $ABSPATH ]; then | |
echo "*** $ABSPATH doesn't exist! ***" | |
exit | |
fi | |
for F in $ABSPATH/*; do | |
if [[ ! "$F" =~ (png|PNG|jpeg|JPEG|jpg|JPG)$ ]]; then | |
echo "*** $F ignored." | |
continue | |
fi | |
F_DATE=`stat -f "%m" "$F"` | |
NEW_F=`/bin/date -r ${F_DATE} +'%Y-%m-%d %H.%M.%S.jpg'` | |
while [[ -e "$ABSPATH/$NEW_F" ]]; do | |
F_DATE=`expr ${F_DATE} + 1` | |
NEW_F=`/bin/date -r ${F_DATE} +'%Y-%m-%d %H.%M.%S.jpg'` | |
done | |
read -p "Rename $F -> ${NEW_F} ? [y/N]" -n 1 -r | |
echo | |
if [[ ! $REPLY =~ ^[Yy]$ ]]; then | |
continue | |
else | |
echo "+ $F -> ${NEW_F}" | |
mv "$F" "$ABSPATH/${NEW_F}" | |
COUNT=`expr $COUNT + 1` | |
fi | |
done | |
echo "$COUNT photos renamed!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment