LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   images creation date newer than last modified date (http://www.linuxquestions.org/questions/linux-newbie-8/images-creation-date-newer-than-last-modified-date-743066/)

fenrisW0lf 07-27-2009 08:40 AM

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.

Troy

dxangel 07-27-2009 08:53 AM

Hello and welcome!

stat would be a good tool to use

heres an example;

[root@foo01 foo]# stat foo.sh

File: `foo.sh'
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

fenrisW0lf 07-28-2009 05:48 PM

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.

Code:

#:~/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?

Code:

#! /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"


fenrisW0lf 07-28-2009 06:04 PM

Figured out how to do this. Just add this line:

Code:

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


All times are GMT -5. The time now is 01:42 AM.