monitor_directory


Description:

public abstract FileMonitor monitor_directory (FileMonitorFlags flags, Cancellable? cancellable = null) throws IOError

Obtains a directory monitor for the given file.

This may fail if directory monitoring is not supported.

If cancellable is not null, then the operation can be cancelled by triggering the cancellable object from another thread. If the operation was cancelled, the error g_io_error_cancelled will be returned.

It does not make sense for flags to contain g_file_monitor_watch_hard_links, since hard links can not be made to directories. It is not possible to monitor all the files in a directory for changes made via hard links; if you want to do this then you must register individual watches with monitor.

Example: Directory monitoring:

public static int main () {
try {
File file = File.new_for_path (Environment.get_home_dir ());
FileMonitor monitor = file.monitor_directory (FileMonitorFlags.NONE, null);
print ("Monitoring: %s\n", file.get_path ());

monitor.changed.connect ((src, dest, event) => {
if (dest != null) {
print ("%s: %s, %s\n", event.to_string (), src.get_path (), dest.get_path ());
} else {
print ("%s: %s\n", event.to_string (), src.get_path ());
}
});

new MainLoop ().run ();
} catch (Error err) {
print ("Error: %s\n", err.message);
}
return 0;
}

valac --pkg gio-2.0 GLib.File.monitor_directory.vala

Parameters:

this

input File

flags

a set of FileMonitorFlags

cancellable

optional Cancellable object, null to ignore

Returns:

a FileMonitor for the given this, or null on error. Free the returned object with unref.