Snippets

Peter Finlayson photo_date_set_mtp.sh

Created by Peter Finlayson last modified
#!/bin/bash -e

# When copying photos etc off an MTP device like a phone, Linux does not preserve the file's mtime.
# This script is designed to work around this 

# STEP 1: Set this
PHOTO_DIR="/run/user/1000/gvfs/mtp:host=%5Busb%3A003%2C017%5D/Phone/DCIM/Camera/"

# STEP 2: You must CD to the folder where the photos are copied to
# STEP 3: do this:
#  for i in *.jpg *.mp4 *.jpeg; do ./photo_date_set "$i"; done

echo "setting time for '$1' from '$PHOTO_DIR'"

timestamp=$(stat -c %Y "$PHOTO_DIR"/"$1")
stat_string=$(date --date @$timestamp +'%Y%m%d%H%M.%S')

touch "$1" -t $stat_string

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.