# Method System.Inotify.Instance()->add_watch()

Method add_watch

  `int add_watch(string filename, int mask, function(int, int, string, mixed ... :void) callback, mixed ... extra)`

Description

  Add a watch for a certain file and a set of events specified by `mask`. The function `callback` will be called when such an event occurs. The arguments to the callback will be the events mask, the cookie, the `filename` and `extra`.

Returns

  Returns a watch descriptor which can be used to remove the watch.

Note

  When adding a second watch for the same file the old one will be removed unless System.Inotify.IN_MASK_ADD is contained in `mask`.

Note

  The mask of an event may be a subset of the mask given when adding the watch.

Note

  In case the watch is added for a regular file, the filename will be passed to the callback. In case the watch is added for a directory, the name of the file to which the event happened inside the directory will be concatenated.