• Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Script to update 'created on' timestamp

Pondlife

Froglike
Joined
May 2, 2006
Messages
13,861
Likes received
1,635
Thanks received
365
Location
Euroland
Maybe a long shot but thought I'd ask.

Background: Every year when we go on hols I forget to update the current date/time on the camera, which means that all the image files have a created on of 01 Jan 2010 + the holiday duration.

I'd like a script/prog/app that I can run in a directory that will update the created on timestamp relative to a specified value. i.e it replaces 01/01/2010 + holiday elapsed time with 16/09/2014 + HET

Any ideas?

TIA

Pondy.
 
Maybe a long shot but thought I'd ask.

Background: Every year when we go on hols I forget to update the current date/time on the camera, which means that all the image files have a created on of 01 Jan 2010 + the holiday duration.

I'd like a script/prog/app that I can run in a directory that will update the created on timestamp relative to a specified value. i.e it replaces 01/01/2010 + holiday elapsed time with 16/09/2014 + HET

Any ideas?

TIA

Pondy.

What operating system?
 
Maybe a long shot but thought I'd ask.

Background: Every year when we go on hols I forget to update the current date/time on the camera, which means that all the image files have a created on of 01 Jan 2010 + the holiday duration.

I'd like a script/prog/app that I can run in a directory that will update the created on timestamp relative to a specified value. i.e it replaces 01/01/2010 + holiday elapsed time with 16/09/2014 + HET

Any ideas?

TIA

Pondy.

If a Unix system (or Unix-like) 'touch -t timestamp_you_want filename(s) - wildcards/regex works in the filename bit.

eg: touch -t 201409161030 pic*.jpg

for a timestamp of 16th of Sept 2014 at 10:30am......

EDIT: reread - this won't do exactly what you want, you'd need to do some awk/sed/grep'ing on a listing to squirt into a for loop.
 
Last edited: 11:54
If a Unix system (or Unix-like) 'touch -t timestamp_you_want filename(s) - wildcards/regex works in the filename bit.

eg: touch -t 201409161030 pic*.jpg

for a timestamp of 16th of Sept 2014 at 10:30am......

EDIT: reread - this won't do exactly what you want, you'd need to do some awk/sed/grep'ing on a listing to squirt into a for loop.


Cheers Stek.
 
In case anyone else is ever looking for something similar, I've pinched this off askubuntu and it works fine on my MBP. Just add in the number of days you want to shift the timestamp by (73days in the case below).

Note: this only updates the 'modified on' if it's later than 'created on' but I'll fiddle when I get the chance.

Ta all.



#!/bin/bash

# find specific files
files=$(find . -type f -name '*.jpg')

# use newline as file separator (handle spaces in filenames)
IFS=$'\n'

for f in ${files}
do
# read file modification date using stat as seconds
# adjust date using date and print in correct format
# change file time using touch
touch -t $(date -v +73d -r $(stat -f %m "${f}") +%Y%m%d%H%M.%S) "${f}"
done
 
In case anyone else is ever looking for something similar, I've pinched this off askubuntu and it works fine on my MBP. Just add in the number of days you want to shift the timestamp by (73days in the case below).

I found that, but couldn't get it to work on my Linux box (which is very out of date now), so didn't post it.

The next step for you to consider is to go through the renamed files and take the new modified date and use that to correct the EXIF data in the image file :D
 

Advertisers

Back
Top