Object Hierarchy:

Object hierarchy for FileMonitor


public abstract class FileMonitor : Object

Monitors a file or directory for changes.

To obtain a FileMonitor for a file or directory, use monitor, monitor_file, or monitor_directory.

To get informed about changes to the file or directory you are monitoring, connect to the changed signal. The signal will be emitted in the thread-default main context of the thread that the monitor was created in (though if the global default main context is blocked, this may cause notifications to be blocked even if the thread-default context is still running).

Example: File monitoring:

public static int main () {
try {
File file = File.new_for_path (Environment.get_home_dir ());
FileMonitor monitor = file.monitor (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.vala

Namespace: GLib
Package: gio-2.0



Creation methods:



Inherited Members: