You Are Here:

Community: Developer Discussion Boards

#1 Old get file last modified time - 2009-04-20, 23:40

Join Date: Feb 2009
Posts: 17
kabinda
Offline
Registered User
Hi all,


I have an app that periodicaly appends data to a log file ( simple text file). I need to check the time the log file was lasted updated. But

Code:
os.path.getmtime(log_file)
returns the time the log_file was created not the last time it was appended. I've also tried using getatime() and getctime() - no good either.


So how do I find out the time a file was last changed - not the time it was created?

Many thanks.
Ian
Reply With Quote

#2 Old Re: get file last modified time - 2009-04-20, 23:47

Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
bogdan.galiceanu's Avatar
bogdan.galiceanu
Offline
Forum Nokia Champion
Hi,

According to this article this should work:
Code:
import os, time
 
 
#Get the information for a file
statinfo = os.stat("C:\\Python\\ball.py")
 
#Display it
print "Last modified: " + time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(statinfo.st_mtime))
Reply With Quote

#3 Old Re: get file last modified time - 2009-04-23, 22:21

Join Date: Feb 2009
Posts: 17
kabinda
Offline
Registered User
Thanks for the suggestion but 'statinfo.st_mtime' returns the same value as 'os.path.getmtime()' and is always the time the file was created not the last time it was written to.
Reply With Quote

#4 Old Re: get file last modified time - 2009-04-23, 22:37

Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
bogdan.galiceanu's Avatar
bogdan.galiceanu
Offline
Forum Nokia Champion
That's strange. I just tested it with PyS60 1.4.5 and 1.9.3 and it worked as expected. I even modified the file a few times and the result was always good.
Reply With Quote

#5 Old Re: get file last modified time - 2009-04-24, 10:49

Join Date: Feb 2009
Posts: 17
kabinda
Offline
Registered User
If it makes a difference, my log file is being written to in append mode - eg :

Code:
log_file = open("log_file.txt","a")
But shouldn't the file's modified time still be updated each time it’s written to?

FYI using 1.4.5
Reply With Quote

#6 Old Re: get file last modified time - 2009-04-24, 13:31

Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
bogdan.galiceanu's Avatar
bogdan.galiceanu
Offline
Forum Nokia Champion
That's exactly how I tried - I added some text to a file in append mode. And the "last modified" time changed accordingly.
Reply With Quote

#7 Old Re: get file last modified time - 2009-04-24, 15:18

Join Date: Feb 2009
Posts: 17
kabinda
Offline
Registered User
I realy am confused now. I have no idea why mine dosn't.

I assume your "last modified" time changes on every append not just the first one?
Reply With Quote

#8 Old Re: get file last modified time - 2009-04-24, 15:46

Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
bogdan.galiceanu's Avatar
bogdan.galiceanu
Offline
Forum Nokia Champion
Yes, it changes after every append. I used the following script which I ran several times and the results were as expected:
Code:
import e32, os, time

 
#Get the information for a file
statinfo = os.stat("C:\\Data\\Python\\file.txt")

#Display time
print "Last modified: " + time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(statinfo.st_mtime))

#Append it
f = open("C:\\Data\\Python\\file.txt", 'a')
f.write("some text")
f.close()

#Get the information for a file
statinfo = os.stat("C:\\Data\\Python\\file.txt")
 
#Display time
print "Last modified: " + time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(statinfo.st_mtime))

#Wait 5 seconds
e32.ao_sleep(5)

#Append it
f = open("C:\\Data\\Python\\file.txt", 'a')
f.write("some text")
f.close()

#Get the information for a file
statinfo = os.stat("C:\\Data\\Python\\file.txt")
 
#Display time
print "Last modified: " + time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(statinfo.st_mtime))
Reply With Quote

#9 Old Re: get file last modified time - 2009-04-24, 19:13

Join Date: May 2007
Posts: 2,737
Location: 21.46 N 72.11 E
croozeus's Avatar
croozeus
Offline
Forum Nokia Champion
Quote:
Originally Posted by kabinda View Post
I realy am confused now. I have no idea why mine dosn't.

I assume your "last modified" time changes on every append not just the first one?
You would need to close the file to get the time updated. Note, Bogdan has closed the file after appending text to it every time.
Reply With Quote

#10 Old Re: get file last modified time - 2009-04-24, 22:01

Join Date: Feb 2009
Posts: 17
kabinda
Offline
Registered User
Right, found the issue. Bogdan - yes your script works but my log_file is on in E: not C: which seems to matter! If you change you script to work with "E:\\Data\\Python\\file.txt" you will see that the last mod time is no longer updated !!

Why does it work on files in C: but not E: Isthis a bug or 'feature'

Thanks guys for your help.
Reply With Quote

#11 Old Re: get file last modified time - 2009-04-26, 10:34

Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
bogdan.galiceanu's Avatar
bogdan.galiceanu
Offline
Forum Nokia Champion
Yes, you're right. I tried with a file on E and it didn't work. If you feel it's necessary, submit a bug report here.
Reply With Quote

#12 Old Re: get file last modified time - 2009-04-29, 05:23

Join Date: Jan 2009
Posts: 6
bao_jm
Offline
Registered User
A reference: check file status with Nokia PC Suite after exicute:

f = open("E(or C,whatever):\\Python\\file.txt", 'a')
f.write("some text")
f.close()

you find on File Manager of the PC Suite that the time of the file remains unchanged. However, it is changed obsolutely if you check with Filebrowser.py on the device!

Jambao
Reply With Quote

#13 Old Re: get file last modified time - 2009-04-30, 21:10

Join Date: Feb 2009
Posts: 17
kabinda
Offline
Registered User
Thanks to all for confirming this issue. I thought I was going mad
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
Playing a mid file and a wav file at the same time mlhamel Mobile Java Media (Graphics & Sounds) 4 2009-06-25 07:03
BasicStructL() panic after the rss file being modified LionC650 General Symbian C++ 12 2009-04-24 11:57
Getting around midlet signing for JSR-75. Timmmm3d Mobile Java Networking & Messaging & Security 3 2008-12-15 00:19
Help needed with a 3gp file... joedoe_1981 Streaming and Video 0 2007-07-18 19:58
求助关于SDK平台变化后系统头文件出错的问题 cxg1103 Symbian 3 2007-03-07 04:36

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d81449X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZpythonQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZuserE5ftagQSxpythonX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ