Directory Watcher

by KoBeWi

42

Godot Directory Watcher

DirectoryWatcher will notify you whenever files or file list has changed in a directory.

Usage

  1. Create the watcher.
var watcher = DirectoryWatcher.new()
add_child(watcher)
  1. Add a directory to watch.
watcher.add_scan_directory("res://directory")

(automatically gets converted to absolute path; you can add more than 1)

  1. Connect signals.
watcher.files_created.connect(on_files_created)
watcher.files_modified.connect(on_files_modified)
watcher.files_deleted.connect(on_files_deleted)
  1. Enjoy.

Some technical info

DirectoryWatcher will periodically crawl over the files in a directory and report all file changes. Sub-directories are ignored and the scan isn't recursive. To reduce I/O operations, the scan runs every second and scans 50 files per frame inside _process() method. Rate of scan and files per frame are configurable with scan_delay and scan_step variables.

watcher.scan_delay = 0.5
watcher.scan_step = 20

The signals are emitted at the end of a scan cycle and files are passed as absolute paths.

You can deregister a directory by using remove_scan_directory(). This will take effect at the end of the current scan cycle. The class has built-in documentation.


You can find all my addons on my profile page.

Version

1.0.1

Engine

4.0

Category

Misc

Download

Version1.0.1
Download

Support

If you need help or have questions about this plugin, please contact the author.

Contact Author