2

Possible Duplicate:
How do I watch a file for changes using Python?
Detect File Change Without Polling

I am trying to write an application which must perform an action when files are modified or added within a particular directory and its sub-directories.

I imagine that an ideal solution would be to bind to some type of system event that is fired by the operating system when a file or directory is modified. Another less-than-ideal solution would be for my application to manually, recursively check for file changes within a directory at a specified time interval, but this could get incredibly process-intensive if there are lots of files that must be checked every few minutes.

Summary: What is the best way for my application to watch for file changes within a directory?

For the scope of this question, assume that my application is written in Python and the operating system is Linux-based, but generalized answers that solve this problem for other languages and operating systems such as Windows or Mac OS are most welcome.

Community
  • 1
  • 1
Richard Keller
  • 1,980
  • 2
  • 19
  • 32
  • Duplicate of http://stackoverflow.com/questions/5738442/detect-file-change-without-polling (there's also http://stackoverflow.com/questions/182197/how-do-i-watch-a-file-for-changes-using-python for Windows). I've voted to close it as a duplicate of the first, I'd appreciate it if if you're voting to close it you make sure the second is also nominated... this can be a good signpost question. Watchdog is, in my opinion, the best answer, anyway. Great cross-platform support. – Chris Morgan Dec 04 '11 at 13:27
  • 1
    Chris, thanks for those links, they answer my question perfectly. I would vote to close, but I don't seem to have the privileges for that yet. This question can be closed as duplicate. – Richard Keller Dec 04 '11 at 13:48

2 Answers2

4

As you have asked the question with Python Tag you may want to check pyinotify

Abhijit
  • 62,056
  • 18
  • 131
  • 204
3

I think libnotify is what you're looking for. You'll find it available for pretty much every language and OS. Here it is for Python/Linux

Miquel
  • 15,405
  • 8
  • 54
  • 87