LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices

Reply
 
Search this Thread
Old 07-27-2009, 07:40 AM   #1
fenrisW0lf
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.

Troy
 
Old 07-27-2009, 07:53 AM   #2
dxangel
Member
 
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 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
 
Old 07-28-2009, 04:48 PM   #3
fenrisW0lf
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.

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"
 
Old 07-28-2009, 05:04 PM   #4
fenrisW0lf
LQ Newbie
 
Registered: Dec 2005
Posts: 16

Original Poster
Rep: Reputation: 0
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
 
  


Reply


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 02:10 PM
shell script to find modified date and last accessed date of any file. parasdua Linux - Newbie 6 04-22-2008 09:59 AM
Created and Modified date linux2man Linux - Newbie 1 08-13-2007 12:10 PM
what is the correct syntax order for tar with --after-date DATE, --newer DAT farhan Linux - General 1 03-16-2007 08:43 AM
php read file creation, modified date problem antony_csf Programming 3 08-18-2004 06:46 AM


All times are GMT -5. The time now is 07:10 PM.

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