Created
December 4, 2018 02:03
-
-
Save laubstein/78f754d08fd2d3bdad38d72c48f3eceb to your computer and use it in GitHub Desktop.
Photo and Video organized by dir
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
#!/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