Monitor specified folder using `gio.FileMonitor`

Hi,

I’m monitoring folder2 using:

const file = Gio.File.new_for_path('/tmp/folder1/folder2')
file.monitor_directory(
    Gio.FileMonitorFlags.WATCH_MOUNTS | 
    Gio.FileMonitorFlags.WATCH_MOVES, null);

But if I rename or remove the parent folder folder1, signal changed never emits. How can I receive changed when I do this?

After I rename to /tmp/folder3/folder2 and add a file to folder2, changed still emits.

How can I only monitor /tmp/folder1/folder2? If folder1 was renamed to folder3 or is moved to trash, I want to monitor /tmp/folder1/folder2, not /tmp/folder3/folder2 and not the one in the trash.

You’d have to additionally monitor each parent directory if you want to receive signals when they are moved.

Moving a directory on the same filesystem doesn’t move its contents.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.