468,290 Members | 1,849 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,290 developers. It's quick & easy.

Using ST_ATIME to watch for files being read

I need to monitor a bunch of files to see what is being opened, read,
and closed, with no modifications being made. This is being done
first on Windows machines, and later on Solaris.

Looking through Python Programming on Win32, I saw the ST_ATIME (page
311) which looked promising, but when I did a little test, the results
weren't good (read: sucked):

# from the i.shell. st_atime date is inside >>><<<
os.stat("c:\\devtemp\\python\\1.txt") (33206, 0L, 2, 1, 0, 0, 3L, >>>1080919329<<<, 1080919329, 1080918583)

# now i open c:\devtemp\python\1.txt, close it, and rerun os.stat("c:\\devtemp\\python\\1.txt")

(33206, 0L, 2, 1, 0, 0, 3L, >>>1080919329<<<, 1080919329, 1080918583)

The Win32 books states that stat.ST_ATIME is "the time the file was
last accessed or zero if the filesystem doesn't support this
information". Obviously I'm missing something, or maybe atime isn't
the best thing for me to use in this situation. Hoping someone can
provide guidance.

TIA
-cjl
Jul 18 '05 #1
1 2160
On 2 Apr 2004 07:39:38 -0800, rumours say that ia*******@hotmail.com
(Chris) might have written:

Hi Chris,
I need to monitor a bunch of files to see what is being opened, read,
and closed, with no modifications being made. This is being done
first on Windows machines, and later on Solaris.
<snip>
# from the i.shell. st_atime date is inside >>><<<
os.stat("c:\\devtemp\\python\\1.txt")(33206, 0L, 2, 1, 0, 0, 3L, >>>1080919329<<<, 1080919329, 1080918583) # now i open c:\devtemp\python\1.txt, close it, and rerun


How exactly do you open the file? Through python or through an external
program (eg notepad)? If only through python, do you read any data? I
believe you have to read data for the access time to be updated.
os.stat("c:\\devtemp\\python\\1.txt")

(33206, 0L, 2, 1, 0, 0, 3L, >>>1080919329<<<, 1080919329, 1080918583)

The Win32 books states that stat.ST_ATIME is "the time the file was
last accessed or zero if the filesystem doesn't support this
information". Obviously I'm missing something, or maybe atime isn't
the best thing for me to use in this situation. Hoping someone can
provide guidance.


Windows has a weird behaviour even with st_mtime... I have a directory
structure in a USB disk, which, taking advantage of NTFS capability for
hard links, I present under two different views for the users of my
network. To avoid re-reading the contents of all files, I keep a cache
of (relative-filename, size, modification time); by comparing the cache
to the actual directory structure, every time I change a couple of
files, I read only the changed ones to decide where in the linked
structures I will present them.

I have found (through trial and error) that the modification time does
not show up immediately, esp. if the file is modified in the linked
directory structures... I tried even using a sync.exe from sysinternals,
but that doesn't change a lot. So, after a change, I wait a couple of
minutes and then I run the python script that relinks the files.
Everything works this way.
--
TZOTZIOY, I speak England very best,
Ils sont fous ces Redmontains! --Harddix
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by jason | last post: by
1 post views Thread by Troy Murphy | last post: by
8 posts views Thread by Sunil Menon | last post: by
5 posts views Thread by Michael Sperlle | last post: by
8 posts views Thread by ronen.chen | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.