OS-independent API to monitor file system?
Asked Answered
F

4

8

I would like to experiment with ideas about distributed file synchronization/replication. To make it efficient when the user is working, I would like to implement some kind of daemon to monitor changes in some directory (e.g. /home/user/dirToBeMonitored or c:\docs and setts\user\dirToBeMonitored). So, I could be able to know which filename was added/changed/deleted at every time (or within a reasonable interval).

Is this possible with any high-medium level language?. Do you know some API (and in which language?) to do this?

Thanks.

Facet answered 30/9, 2008 at 22:59 Comment(1)
OP is asking for a cross-platform solution, none of the answers below address this. Ideally such a solution should be implemented in a low-level language like C++ then provide bindings to various high-level languages ie PythonTwomey
T
9

A bonified answer, albeit one that requires a largish library dependency (well-worth it IMO)!

QT provides the QFileSystemwatcher class, which uses the native mechanism of the underlying platform.

Even better, you can use the QT language bindings for Python or Ruby. Here is a simple PyQT4 application which uses QFileSystemWatcher.

Notes

  • A good reference on on creating deployable PyQT4 apps, especially on OSX but should work for Windows also.
  • Same solution previously posted here.
  • Other cross-platform toolkits may also do the trick (for example Gnome's GIO has GFileMonitor, although it is UNIX only and doesn't support OSX's FSEvents mechanism afaik).
Twomey answered 18/7, 2009 at 17:15 Comment(0)
C
10

The APIs are totally different for Windows, Linux, Mac OS X, and any other Unix you can name, it seems. I don't know of any cross-platform library that handles this in a consistent way.

Counterfeit answered 1/10, 2008 at 0:9 Comment(0)
T
9

A bonified answer, albeit one that requires a largish library dependency (well-worth it IMO)!

QT provides the QFileSystemwatcher class, which uses the native mechanism of the underlying platform.

Even better, you can use the QT language bindings for Python or Ruby. Here is a simple PyQT4 application which uses QFileSystemWatcher.

Notes

  • A good reference on on creating deployable PyQT4 apps, especially on OSX but should work for Windows also.
  • Same solution previously posted here.
  • Other cross-platform toolkits may also do the trick (for example Gnome's GIO has GFileMonitor, although it is UNIX only and doesn't support OSX's FSEvents mechanism afaik).
Twomey answered 18/7, 2009 at 17:15 Comment(0)
D
0

In Linux it is called inotify.

Danais answered 30/9, 2008 at 23:43 Comment(0)
A
0

And on OS X it's called fsevents. It's an OS-level API, so it's easiest to access from C or C++. It should be accessible from nearly any language, although bindings for your preferred language may not have been written yet.

Aten answered 1/10, 2008 at 0:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.