BetterFileWatching.watch_fileMethod
watch_file(f::Function, filename::AbstractString)

Watch a file recursively for any changes. A FileEvent is passed to the callback function f when a change occurs.

Use the single-argument watch_file(filename::AbstractString) to create a blocking call until the file changes (like the FileWatching standard library).

Example

watch_file("file.txt") do event
    @info "Something changed!" event
end

You can watch a file asynchronously, and interrupt the task later:

watch_task = @async watch_file("file.txt") do event
    @info "Something changed!" event
end

sleep(5)

# stop watching the file
schedule(watch_task, InterruptException(); error=true) 

Differences with the FileWatching stdlib

BetterFileWatching.watch_folderFunction
watch_folder(f::Function, dir=".")

Watch a folder recursively for any changes. Includes changes to file contents. A FileEvent is passed to the callback function f.

Use the single-argument watch_folder(dir::AbstractString=".") to create a blocking call until the folder changes (like the FileWatching standard library).

Example

watch_folder(".") do event
    @info "Something changed!" event
end

You can watch a folder asynchronously, and interrupt the task later:

watch_task = @async watch_folder(".") do event
    @info "Something changed!" event
end

sleep(5)

# stop watching the folder
schedule(watch_task, InterruptException(); error=true) 

Differences with the FileWatching stdlib

  • BetterFileWatching.watch_folder works recursively, i.e. subfolders are also watched.
  • BetterFileWatching.watch_folder also watching file contents for changes.
  • BetterFileWatching.jl is based on Deno.watchFs, made available through the Deno_jll package.