Skip to content

Instantly share code, notes, and snippets.

@laubstein
Created December 4, 2018 02:03
Show Gist options
  • Save laubstein/78f754d08fd2d3bdad38d72c48f3eceb to your computer and use it in GitHub Desktop.
Save laubstein/78f754d08fd2d3bdad38d72c48f3eceb to your computer and use it in GitHub Desktop.
Photo and Video organized by dir
#!/usr/bin/bash
# JPG
find . -type f -iname "*.jpg" -print0 | xargs -0 -n1 -I % sh -c 'touch % -d "$(file %|grep -oP "datetime=\K[^,]*"|sed -e "s/:/-/"|sed -e "s/:/-/")"'
# MP4
find . -type f -iname "*.mp4" -print0 | xargs -0 -n1 -I % sh -c 'touch "%" -d "$(exiftool -s -s -s -CreateDate "%"|grep -oP "[0-9]{4}:[0-9]{2}:[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}"|grep -v 0000|sed -e "s/:/-/"|sed -e "s/:/-/")"'
# VID-20181028-WA0001.mp4
find . -type f -iname "VID-*-*.mp4" -print0 | xargs -0 -n1 -I % sh -c 'touch "%" -d "$(echo -n "%"|grep -oP "[0-9]{8}"|sed -r "s/([0-9]{4})([0-9]{2})([0-9]{2})/\1-\2-\3 12:00:00/")"'
# IMG-20141007-WA0002.jpg
find . -type f -iname "IMG-*-*.jpg" -print0 | xargs -0 -n1 -I % sh -c 'touch "%" -d "$(echo -n "%"|grep -oP "[0-9]{8}"|sed -r "s/([0-9]{4})([0-9]{2})([0-9]{2})/\1-\2-\3 12:00:00/")"'
# Organizar arquivos baseado na sua data
for f in *.jpg; do
filedate=`ls --time-style=+%y/%m/%d -l $f | cut --delimiter=' ' -f 6`
if [ ! -d "./${filedate}" ]
then
echo "Creating ./${filedate}"
mkdir -p "./${filedate}"
fi
mv "$f" "./${filedate}/$f"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment