summaryrefslogtreecommitdiff
path: root/dcimrename
blob: f04ae1e9d1ff6e1b85587db1b206e6ba97f97857 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/sh

if [ -z "$1" ]; then
	echo "Rename file to IMG_yyyyddmm_hhmmss.jpg using the EXIF timestamp."
	echo "usage: $0 file1.jpg file2.jpg ..."
	exit 0
fi

while [ ! -z "$1" ]; do
	file="$1"

	if [ `basename "${file}" ".jpg"`".jpg" = "${file}" ]; then
	
		echo "renaming $file"

		# set file timestamp from exif data
		exiftool "-DateTimeOriginal>FileModifyDate" "${file}"

		# get timestamp from file
		#file_timestamp=`date -r "${file}" +"IMG_%Y%m%d_%H%M%S%2N"`
		
		file_timestamp=`date -r "${file}" +"IMG_%Y%m%d_%H%M%S"`
		mv "${file}" "${file_timestamp}.jpg"
	fi

	shift
done