Skip to content

Instantly share code, notes, and snippets.

@yilozt
Created July 23, 2022 16:09
Show Gist options
  • Save yilozt/775d31281f6c55341222fdd7400fc759 to your computer and use it in GitHub Desktop.
Save yilozt/775d31281f6c55341222fdd7400fc759 to your computer and use it in GitHub Desktop.
Watch Directory With Gio
const GLib = imports.gi.GLib
const Gio = imports.gi.Gio
const loop = new GLib.MainLoop (null, false)
const home = GLib.get_home_dir ()
const file = Gio.File.new_for_path (home + '/a/b')
const monitor = file.monitor (Gio.FileMonitorFlags.WATCH_MOVES, null)
monitor.connect ('changed', (monitor, file, otherFile, eventType) => {
log (monitor)
switch (eventType) {
case Gio.FileMonitorEvent.CREATED:
console.log (`${file.get_path ()} was created`)
}
})
loop.run ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment