Is there a file watchdog concept in julia

Hi All
I am experimenting with some thoughts about how I want to use julia. One of them is to keep an eye on a directory and watch for interesting events. Some examples

  • file creation
  • file deletion
  • file modification
  • file move

An example in python ( not my code) is below. I don’t really want to wrapper it in pycall IF there is a builtin or Pkg that does it already as I am trying to leave python behind.

I have searched around but I can’t seem to find anything. Any pointers would be welcome.


# https://thepythoncorner.com/posts/2019-01-13-how-to-create-a-watchdog-in-python-to-look-for-filesystem-changes/

import time
from watchdog.observers import Observer
from watchdog.events import PatternMatchingEventHandler



def on_created(event):
    print(f"hey, {event.src_path} has been created!")

def on_deleted(event):
    print(f"what the ! Someone deleted {event.src_path}!")

def on_modified(event):
    print(f"hey buddy, {event.src_path} has been modified")

def on_moved(event):
    print(f"ok ok ok, someone moved {event.src_path} to {event.dest_path}")


if __name__ == "__main__":
    
    patterns = ["*"]
    ignore_patterns = None
    ignore_directories = False
    case_sensitive = True
    
    my_event_handler = PatternMatchingEventHandler(patterns, ignore_patterns, ignore_directories, case_sensitive)

    
    my_event_handler.on_created = on_created
    my_event_handler.on_deleted = on_deleted
    my_event_handler.on_modified = on_modified
    my_event_handler.on_moved = on_moved

    path = "."
    go_recursively = True
    my_observer = Observer()
    my_observer.schedule(my_event_handler, path, recursive=go_recursively)

    
    my_observer.start()
    try:
       while True:
            time.sleep(1)
    except KeyboardInterrupt:
        my_observer.stop()
        my_observer.join()

There is the FileWatching stdlib: https://docs.julialang.org/en/v1/stdlib/FileWatching/

5 Likes

hey @ericphanson I’ll certainly check that out. I did see it but I rushed past it thinking it was just a file watcher. For some reason, stupidity, I forgot that ALL things in linux are a file… Thanks for the nudge back to the right path.