Skip to content

Latest commit

 

History

History
44 lines (32 loc) · 1.72 KB

README.md

File metadata and controls

44 lines (32 loc) · 1.72 KB

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.connect("files_created", self, "on_files_created")
watcher.connect("files_modified", self, "on_files_modified")
watcher.connect("files_deleted", self, "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 next scan cycle.


You can find all my addons on my profile page.

Buy Me a Coffee at ko-fi.com