Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 07-27-2009, 08:40 AM   #1
LQ Newbie
Registered: Dec 2005
Posts: 16

Rep: Reputation: 0
images creation date newer than last modified date

Hi all,

I have recently switched my desktop environment over to Ubuntu from windows xp. I must say that I haven't had this much fun since going from windows 3.1 to windows 95!

I am having a minor difficulty and can't seem to figure it out. I am currently setting up digikam to manage my photo collection. I noticed in the calendar view that I have about 200 or so pictures that have a creation date that is newer then the last modified date.

I was wondering how to swap the values. I have always named my pictures with the dates in the names and the last modified date is the date these pictures were taken.

Is there an easy way to accomplish this? If not what tools would I need to be able to extract the creation time and last modified time so that I can re-write the values using some sort of script. I also noticed (through digikam) that these images don't have any exif information (or any metadata) stored within the pictures. So the dates that digikam is using are the actually file dates.

Old 07-27-2009, 08:53 AM   #2
Registered: Nov 2008
Location: London, UK
Distribution: CentOS, RedHat, Ubuntu
Posts: 79

Rep: Reputation: 18
Hello and welcome!

stat would be a good tool to use

heres an example;

[root@foo01 foo]# stat

File: `'
Size: 1328 Blocks: 8 IO Block: 4096 regular file
Device: 811h/2065d Inode: 605539 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 1006/ foo) Gid: ( 10/ wheel)
Access: 2009-07-24 14:26:01.000000000 +0100
Modify: 2009-07-24 14:25:35.000000000 +0100
Change: 2009-07-24 14:25:42.000000000 +0100
Old 07-28-2009, 05:48 PM   #3
LQ Newbie
Registered: Dec 2005
Posts: 16

Original Poster
Rep: Reputation: 0
dxangel, thanks for the reply.

You information about stats was what I was looking for.

Here is the results of the stats on one of the images that is causing problems.

#:~/pictures/2004/10$ stat 2004-10-01_163900.jpg 
File: `2004-10-01_163900.jpg'
Size: 1193225   	Blocks: 2336       IO Block: 4096   regular file
Device: 804h/2052d	Inode: 133334      Links: 1
Access: (0777/-rwxrwxrwx)  Uid: ( 1000/    troy)   Gid: ( 1000/    troy)
Access: 2009-07-23 18:38:29.212744000 -0400
Modify: 2004-10-01 17:39:00.000000000 -0400
Change: 2009-07-23 18:38:29.240747160 -0400
As you can see the Modify date is older then the other two. I am not sure which date digikam is using since the exif and iptc information is missing for the images. What I would like to do is reset all the date values to match the modified date.

I coded up some python that searches a folder for images that have an access date that is newer then the modified, but I don't know how to reset all of the time values to match?

#! /usr/bin/env python

import os, fnmatch, sys, time, stat

def locate(pattern, root=os.curdir):
	for path, dirs, files in os.walk(os.path.abspath(root)):
		for filename in fnmatch.filter(files, pattern):
			yield os.path.join(path, filename)

if __name__ == '__main__':
	path = '/home/troy/pictures/2004/10/'
	pattern = '*.jpg'
	for item in locate(pattern, path):
		stats = os.stat(item) 
		if time.localtime(stats[stat.ST_MTIME]) < time.localtime(stats[stat.ST_CTIME]):
			print "file = ", os.path.basename(item), " creation time newer than last modified"
Old 07-28-2009, 06:04 PM   #4
LQ Newbie
Registered: Dec 2005
Posts: 16

Original Poster
Rep: Reputation: 0
Figured out how to do this. Just add this line:

os.utime(item, (os.stat(item)[stat.ST_MTIME], os.stat(item)[stat.ST_MTIME]))
to the bottom of the main loop after the print statement


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Modified Date kernelzack Programming 25 07-05-2009 03:10 PM
shell script to find modified date and last accessed date of any file. parasdua Linux - Newbie 6 04-22-2008 10:59 AM
Created and Modified date linux2man Linux - Newbie 1 08-13-2007 01:10 PM
what is the correct syntax order for tar with --after-date DATE, --newer DAT farhan Linux - General 1 03-16-2007 09:43 AM
php read file creation, modified date problem antony_csf Programming 3 08-18-2004 07:46 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:34 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration