FileMonitor#

class ignis.utils.FileMonitor(path: str, recursive: bool = False, flags: str | None = None, callback: Callable | None = None, prevent_gc: bool = True)#

Monitor changes of the file or directory.

Example usage:

Utils.FileMonitor(
    path="path/to/something",
    recursive=False,
    callback=lambda path, event_type: print(path, event_type),
)
changed(*args)#
  • Signal

Emitted when the file or directory changed.

Parameters:
  • path (str) -- The path to the changed file or directory.

  • event_type (str) -- The event type. A list of all event types described in callback.

property path: str#
  • required, read-only

The path to the file or directory to be monitored.

property flags: str | None#
  • optional, read-only

What the monitor will watch for.

Possible values:

  • none

  • watch_mounts

  • send_moved

  • watch_hard_links

  • watch_moves

See Gio.FileMonitorFlags for more info.

Default: None.

property callback: Callable | None#
  • optional, read-write

A function to call when the file or directory changes. It should take two arguments: 1. The path to the changed file or directory 2. The event type.

Default: None.

Event types:

  • changed

  • changes_done_hint

  • moved_out

  • deleted

  • created

  • attribute_changed

  • pre_unmount

  • unmounted

  • moved

  • renamed

  • moved_in

See Gio.FileMonitorEvent for more info.

property recursive: bool#
  • optional, read-only

Whether monitoring is recursive (monitor all subdirectories and files).

Default: False.

property prevent_gc: bool#
  • optional, read-only

Whether to prevent the garbage collector from collecting this file monitor.

Default: True.

cancel() None#

Cancel the monitoring process.

Return type:

None