DirectoryWatcher will notify you whenever files or file list has changed in a directory.
Usage
- Create the watcher.
var watcher = DirectoryWatcher.new()
add_child(watcher)
- Add a directory to watch.
watcher.add_scan_directory("res://directory")
(automatically gets converted to absolute path; you can add more than 1)
- Connect signals.
watcher.files_created.connect(on_files_created)
watcher.files_modified.connect(on_files_modified)
watcher.files_deleted.connect(on_files_deleted)
- Enjoy.

Editor usage
DirectoryWatcher is a Node, so it can be set up from the editor too. Just add it to the scene and inspect.


Note that the list of directories set from the inspector can't be modified after the watcher node is ready. Also it does not allow to assign paths from outside the project.
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.
Changelog for version 1.1
No changelog provided for this version.