Skip to content

Commit

Permalink
fix: time from filename for imsges
Browse files Browse the repository at this point in the history
  • Loading branch information
davidecavestro committed Jun 5, 2024
1 parent f964ce7 commit b028813
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions save.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function do_image () {

echo "PARENT_DIR: $PARENT_DIR"

local creation_time=$(exiftool -CreateDate -d "%Y-%m-%d %H:%M:%S" "$FILE" | awk -F ': ' '{print $2}')
local creation_time=$(exiftool -DateTimeOriginal -d "%Y-%m-%d %H:%M:%S" "$FILE" | awk -F ': ' '{print $2}')

local filename=$(basename $FILE)
# If creation_time is not available, try getting it from filename
Expand All @@ -37,14 +37,22 @@ function do_image () {

# Create a formatted timestamp
creation_time="$year-$month-$day $hour:$minute:$second"

exiftool "-DateTimeOriginal=${creation_time}" -overwrite_original "$FILE"
# Check if the command was successful
if [[ $? -eq 0 ]]; then
echo "DateTimeOriginal has been set to $creation_time for $FILE"
else
echo "Failed to set DateTimeOriginal for $FILE"
fi
fi
fi

# set file time
exiftool "-DateTimeOriginal>FileModifyDate" $FILE

# move file to proper subdir
exiftool -d "${PARENT_DIR}/%Y/%Y-%m" '-directory<${CreateDate}' '-filename<${filename}' $FILE
exiftool -d "${PARENT_DIR}/%Y/%Y-%m" '-directory<${DateTimeOriginal}' '-filename<${filename}' $FILE

# move to destination folder
cd $PARENT_DIR
Expand Down

0 comments on commit b028813

Please sign in to comment.