473,789 Members | 2,500 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to tell when a file is opened

Hello,

I want to know if it possible to tell when a file is opened. However I
don't want it to be the last access time. I want to know how many
times a file opened so I can generate statistics of file usage.

I will be wanting to watch all files on a server so this will be on
quite a large scale. So checking a directory on a loop for accesses
won't work.

Maybe some way to monitor the Open Files section of Computer
Management?

I check through Tim Golden's site but nothing jumped out at me.
Any pointers would be great.

Thanks,
Adam

Apr 7 '07 #1
7 2450
Adam wrote:
I want to know if it possible to tell when a file is opened. However I
don't want it to be the last access time. I want to know how many
times a file opened so I can generate statistics of file usage.

I will be wanting to watch all files on a server so this will be on
quite a large scale. So checking a directory on a loop for accesses
won't work.

Maybe some way to monitor the Open Files section of Computer
Management?

I check through Tim Golden's site but nothing jumped out at me.
Any pointers would be great.
I take it from the fact that you mention my site (and
your reference to "Computer Management") that you're
looking at Win32? It's always best to be explicit when
you're asking for help; a lot of people on this list
will be using Linux or Mac where the answers are
probably very different.

This is no small task you've set yourself! As far as I know,
you're going to have to go down to the level of change journals
for this kind of thing. (Search for "NTFS change journal").

Although you might think: the filesystem knows when files are
being accessed; can't I hook into that directly? I think the
answer is: no. But I could be wrong.

TJG
Apr 7 '07 #2

"Adam" <ad**********@g ooglemail.comwr ote in message
news:11******** **************@ y80g2000hsf.goo glegroups.com.. .
| Hello,
|
| I want to know if it possible to tell when a file is opened.

Just by Python? (Hack the file and open and possibly os.open code)
or by any program? (Hack the OS -- good luck!)

Apr 7 '07 #3
On Apr 7, 5:09 pm, Tim Golden <m...@timgolden .me.ukwrote:
Adam wrote:
I want to know if it possible to tell when a file is opened. However I
don't want it to be the last access time. I want to know how many
times a file opened so I can generate statistics of file usage.
I will be wanting to watch all files on a server so this will be on
quite a large scale. So checking a directory on a loop for accesses
won't work.
Maybe some way to monitor the Open Files section of Computer
Management?
I check through Tim Golden's site but nothing jumped out at me.
Any pointers would be great.

I take it from the fact that you mention my site (and
your reference to "Computer Management") that you're
looking at Win32? It's always best to be explicit when
you're asking for help; a lot of people on this list
will be using Linux or Mac where the answers are
probably very different.

This is no small task you've set yourself! As far as I know,
you're going to have to go down to the level of change journals
for this kind of thing. (Search for "NTFS change journal").

Although you might think: the filesystem knows when files are
being accessed; can't I hook into that directly? I think the
answer is: no. But I could be wrong.

TJG
Sorry about not mentioning my platform.

What you mention looks promising. Will look into it. Like I said
knowing the last access time is not useful as I would have to be
constantly looping through the directory looking for changes.

Will look into NTFS change journals when I get some spare time.

Thanks for the reply.
Adam

Apr 7 '07 #4
Adam wrote:
On Apr 7, 5:09 pm, Tim Golden <m...@timgolden .me.ukwrote:
Adam wrote:
I want to know if it possible to tell when a file is opened. However I
don't want it to be the last access time. I want to know how many
times a file opened so I can generate statistics of file usage.
You may look into some tools like FileMon and Process Monitor from
www.sysinternals.com; I think that doing the processing in Python
would slow down your system a lot (or not, just try!)

--
Gabriel Genellina

Apr 7 '07 #5
On Apr 7, 8:02 pm, "Gabriel Genellina" <gagsl-...@yahoo.com.a rwrote:
Adam wrote:
On Apr 7, 5:09 pm, Tim Golden <m...@timgolden .me.ukwrote:
Adam wrote:
I want to know if it possible to tell when a file is opened. However I
don't want it to be the last access time. I want to know how many
times a file opened so I can generate statistics of file usage.

You may look into some tools like FileMon and Process Monitor fromwww.sysinte rnals.com;I think that doing the processing in Python
would slow down your system a lot (or not, just try!)

--
Gabriel Genellina
You see I was mainly hoping that python would not be doing the
processing per se. More that, as Tim put it, it would hook itself into
whatever monitors the shares to see when files are open and dump that
info somewhere (like a database or xml) then at a set time (at night
for example) Python would take that information collect it into
historical logs and update a web page with recent stats.

Obviously I have to check that the most vital part is even possible or
at least within my limit programming knowledge (which is why I ask
here.)

Adam

Apr 7 '07 #6
Will look into NTFS change journals when I get some spare time.
How can we get NTFS change journals? Is there any API for this purpose
or we could implement our own?
there're an api in windows help us montior file changes.
win32file.ReadD irectoryChanges W
Apr 8 '07 #7
momobear wrote:
>Will look into NTFS change journals when I get some spare time.
How can we get NTFS change journals? Is there any API for this purpose
or we could implement our own?
there're an api in windows help us montior file changes.
win32file.ReadD irectoryChanges W
Don't know what the API is but whatever it ends up being,
there's always ctypes. This article:

http://www.codeproject.com/useritems/Eyes_on_NTFS.asp

points to DeviceIOControl and CreateFile, both in the
win32file module.

The problem with win32file.ReadD irectoryChanges W, which the
OP probably saw when he looked at my site (though he doesn't
actually say so) is that you're trying to monitor *an entire
hard disk*, maybe more. And you'll almost certainly run into
buffer shortfalls or even performance issues. But I don't
really have access to a big enough or used enough disk to
carry out a meaningful test.

TJG

Apr 8 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
3022
by: Peter Abel | last post by:
Hi all, I'm working under W2k with Python 2.2.2 (#37, Oct 14 2002, 17:02:34) on win32 I have a file *test_data.txt* with the following content: 0123456789 0123456789 abcdefghi ABCDEFGHIJKLMNOPQ
3
5505
by: Romain | last post by:
Hello, I am writing out a binary file. I figured that the number "10" is automaticaly converted to "OD OA" instead of "OD". "OD" and "OA" are line feed and carriage return. I know it does that if the file is opened in something else than in binary mode. But in my example below, the file is really opened in binary.
2
19558
by: Daniel Reber | last post by:
I have an application that is sending a file to a location on a network. I have a windows service that is monitoring that location for new files and then processing them. Sometimes the service tries to process them before that are copied over completely. How can I tell if the other application is done copying the file over? Thanks Dan Reber
6
5170
by: Ana | last post by:
Hi! I have problems with the following scenario: My application is developed using C# under .NET. It must run on all Windows versions starting from Windows 98. The user must open different documents (txt, MS Office files, pdf, pictures,…) from inside my app. It must start the file with the adequate external program (Notepad, MS Office programs, Acrobat Reader, some Picture viewer,... ) and be notified when this programs closes the...
1
1399
by: kscdavefl | last post by:
When I use the OleDbDataProvider to get info from an access database I get the following error: The Microsoft Jet database engine cannot open the file 'C:\Documents and Settings\bailedl1\Desktop\Dave's Docs\DemoData.mdb'. It is already opened exclusively by another user, or you need permission to view its data. I have granted full control permission to the ISUR user with no results. What do I need to do to solve this problem?
7
14006
by: emanshu | last post by:
HI all, I an designing an application in C++. i want to open file requested by end user but i want to reflect an error to user if file is already opened by some other application.. will anybody tell me that how to know that the file is already open or closed.. any help is highly appreciated...
18
7694
by: shilpa.saraogi | last post by:
Heya all, How do I tell, prgrammatically, if a file is opened for read/write by some other process? In unix .. of course. My program needs to open files and work on it, and I want it to make sure that the file is not being written to (e.g. by scp, cp, mv etc) before I attampt to open it. Is there any function to see the status of the file ? Using/implementing locking mechanism is out of the question. If not provided by the language,...
4
2953
by: Peter | last post by:
Access 2007 optionally opens forms as tabs. There is an Access Option that controls this - Access Options Current Database Document Window Options Tabbed Documents. But how, from VBA, can I programmatically tell whether or not a form is opened in Tabbed or Overlapping mode? I tried using Application.GetOption("Document Window Options")
2
10895
by: BAnderton | last post by:
Greetings from beautiful Tucson, Arizona. Question: Is there a way in Python to determine what all file identifiers have been opened by Python, and to close them all? Why I ask: I learned Python after cutting my programming teeth on Matlab, where you get a list of all open file identifiers (that is, those opened from a particular Matlab session) with "fopen('all')" and close them with "fclose('all')". In my 4 years of experience...
0
9663
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10195
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9979
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6765
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5415
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4090
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3695
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2906
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.