| Reply | « Previous Thread | Next Thread » |
|
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) So how do I find out the time a file was last changed - not the time it was created? Many thanks. Ian |
|
Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
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))
|
|
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.
![]() |
|
Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
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.
|
|
If it makes a difference, my log file is being written to in append mode - eg :
Code:
log_file = open("log_file.txt","a")
FYI using 1.4.5 |
|
Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
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.
|
|
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? |
|
Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
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))
|
|
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.
|
|
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. |
|
Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
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.
|
|
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 |
|
Thanks to all for confirming this issue. I thought I was going mad
![]() |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |
| 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 |