Set modification date and time from filename: Difference between revisions
From WickyWiki
mNo edit summary |
mNo edit summary |
||
| Line 27: | Line 27: | ||
done | done | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 18:07, 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.
#!/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}\""
fi
done