Last active
November 21, 2022 19:14
-
-
Save daniambrosio/778fe29052a07c1b3cd91245ec279fd8 to your computer and use it in GitHub Desktop.
Bash Command Line Script to set date and time of files (photos) based on their filename
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/bash | |
# do not forget to run chmod 755 on this script | |
for i in *.mp4; do | |
#file format is: YYYYmmdd_hhmmss | |
echo "$i" | |
day="${i:6:2}" | |
month="${i:4:2}" | |
year="${i:0:4}" | |
hour=${i:9:2} | |
min=${i:11:2} | |
sec=${i:13:2} | |
echo "$day/$month/$year $hour:$min:$sec" | |
# set the creation adn modificiation dates of the file | |
# Format is YYYYmmddhhmm.ss | |
# touch -t "${i:0:8}${i:9:4}.${i:13:2}" "$i" | |
# SET the exif tag dates in the file | |
# Format is YYYY:mm:dd hh:mm:ss | |
exiftool -AllDates="$year:$month:$day $hour:$min:$sec" "$i" | |
# use SetFile to set the date and time params (instead of touch) | |
# Format is MM/DD/YYYY HH:MM:SS | |
# echo "${i:4:2}/${i:6:2}/${i:0:4} ${i:9:2}:${i:11:2}:${i:13:2}" | |
SetFile -d "$month/$day/$year $hour:$min:$sec" "$i" | |
SetFile -m "$month/$day/$year $hour:$min:$sec" "$i" | |
# SHOW the exif tag dates in the file | |
exiftool -a -G1 -s -AllDates "$i" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment