Set modification date and time from filename: Difference between revisions

From WickyWiki
mNo edit summary
mNo edit summary
 
Line 3: Line 3:
[[Category:201502]]
[[Category:201502]]


Set the file 'modified date' from the filename of the form "yyyyMMdd-hhmm*.jpg" or "yyyyMMdd-*.jpg", this script returns the statements.
Set the file 'modified date' from the filename of the form "yyyyMMdd-hhmm*.jpg" or "yyyyMMdd-*.jpg", this script returns the statements.
 
Using the tool ''jhead'' the jpg Exif date/time can be set from the filename.


<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
Line 24: Line 26:
else
else
echo "touch -t \"${year}${month}${day}${hour}${minute}\" \"${file}\""
echo "touch -t \"${year}${month}${day}${hour}${minute}\" \"${file}\""
echo "jhead -ts$year:$month:$day-$hour:$minute:00 \"$file\""
fi
fi
done
done
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 18:13, 24 February 2015


Set the file 'modified date' from the filename of the form "yyyyMMdd-hhmm*.jpg" or "yyyyMMdd-*.jpg", this script returns the statements.

Using the tool jhead the jpg Exif date/time can be set from the filename.

#!/bin/bash
for file in *.jpg
do
	year=${file:0:4}
	month=${file:4:2}
	day=${file:6:2}
	hour=${file:9:2}
	minute=${file:11:2}
	if ! [ "${hour}${minute}" -eq "${hour}${minute}" ] 2> /dev/null
	then
		hour="00"
		minute="00"
	fi
	if ! [ "${year}${month}${day}" -eq "${year}${month}${day}" ] 2> /dev/null
	then
		echo "#'$file' not containing a date"
	else
		echo "touch -t \"${year}${month}${day}${hour}${minute}\" \"${file}\""
		echo "jhead -ts$year:$month:$day-$hour:$minute:00 \"$file\""
	fi
done