0

With ActiveState Python comes a win32api module. I need to implement something that monitors directories recursively for file-changes. Actually there's an example in the MSDN library using C. I don't know whether the win32api bindings are sufficient for something like this.

Can I import this into a Python project? Because it may be easier to write the file-alteration monitor itself in C, and to handle the results within Python. The problem is: how do I make that interact with each other.

4
  • 1
    It would be significantly easier to write the directory watcher in Python. It's basically three or four lines: os.walk, checking what you see against some stored list of what you was last time. Commented Oct 26, 2010 at 22:29
  • 1
    @katrielalex I think he wants something kernel-level like inotify Commented Oct 26, 2010 at 22:31
  • 2
    @katrielalex: @user59300: Yes, but using windows native event system is better. It is similar to pyinotify that is used on Linux. See the link below. Commented Oct 26, 2010 at 22:32
  • 1
    @user59300: Tim Golden's example is what you are looking for. Commented Oct 26, 2010 at 22:34

2 Answers 2

4

Why not try some of the python win32 examples here. It uses pywin32 and does what you want.

The "C" code that you have mentioned with link to MSDN uses FindFirstChangeNotification. Tim Golden's example uses the same through python win32 bindings. I guess this is what you want.

All windows APIs are exposed and can be utilized via pywin32.

Sign up to request clarification or add additional context in comments.

2 Comments

Note that what that page says about ReadDirectoryChangesW blocking so you can't exit the loop, is not a limitation of the Win32 API. Not sure whether you can do overlapped I/O in python though.
What exactly do you have in mind regarding Twisted - sounds very interesting ;)
2

Read the documentation and try it out for yourself. win32file.FindFirstChangeNotification, etc. are there and work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.