Created
November 16, 2020 23:55
-
-
Save averagesecurityguy/9c853157da6394af15659ef1926ae157 to your computer and use it in GitHub Desktop.
Extract the creation date from an image and add the date to the filename. Only works on Mac.
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 | |
# | |
# Extract the creation date from an image and add the date to the filename. | |
# Only works on Mac. | |
# | |
DUMP_DIR="/Users/family/pics/dump" | |
CP_DIR="/Users/family/pics/dated" | |
cd "$DUMP_DIR" | |
OLDIFS=$IFS | |
IFS=$'\n' | |
for file in $(ls); do | |
date=$(mdls "$file" | grep "kMDItemContentCreationDate " | cut -d '=' -f 2 | cut -d ' ' -f 2) | |
newfile=$(echo "$date-$file") | |
echo "cp $file $CP_DIR/$newfile" | |
cp "$file" "$CP_DIR/$newfile" | |
done | |
IFS=$OLDIFS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment