All Projects → p-ranav → fswatch

p-ranav / fswatch

Licence: MIT license
File/Directory Watcher for Modern C++

Programming Languages

C++
36643 projects - #6 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to fswatch

Notify
🔭 Cross-platform filesystem notification library for Rust.
Stars: ✭ 1,123 (+1905.36%)
Mutual labels:  filesystem, watcher
watcherd
A shell daemon that will listen for directory changes and execute custom commands for each event.
Stars: ✭ 48 (-14.29%)
Mutual labels:  inotify, watcher
rorshach
A watchman for your directories. Rorshach allows you to listen to file system changes and run commands when these events occur.
Stars: ✭ 26 (-53.57%)
Mutual labels:  filesystem, watcher
chokidar-socket-emitter
a simple chokidar watcher which emits events to all connected socket.io clients
Stars: ✭ 28 (-50%)
Mutual labels:  filesystem, watcher
watcher
The file system watcher that strives for perfection, with no native dependencies and optional rename detection support.
Stars: ✭ 37 (-33.93%)
Mutual labels:  filesystem, watcher
SwiftFSWatcher
A simple easy to use / extend File System watcher using Swift
Stars: ✭ 35 (-37.5%)
Mutual labels:  filesystem, watcher
PHP-File-Cache
Light, simple and standalone PHP in-file caching class
Stars: ✭ 34 (-39.29%)
Mutual labels:  filesystem, mit-license
Chokidar
Minimal and efficient cross-platform file watching library
Stars: ✭ 8,538 (+15146.43%)
Mutual labels:  filesystem, watcher
gowatch
watch go files for developer, support run test case and auto reload server application
Stars: ✭ 18 (-67.86%)
Mutual labels:  inotify, watcher
kalend
React calendar component with support for multiple views and events
Stars: ✭ 135 (+141.07%)
Mutual labels:  events
vsSolutionBuildEvent
🎛 Event-Catcher with variety of advanced Actions to service projects, libraries, build processes, runtime environment of the Visual Studio, MSBuild Tools, and …
Stars: ✭ 66 (+17.86%)
Mutual labels:  events
Winter
Winter is a 2D game engine for Pharo Smalltalk
Stars: ✭ 43 (-23.21%)
Mutual labels:  mit-license
talksearch
🎤 An interactive search experience for video titles and transcripts
Stars: ✭ 24 (-57.14%)
Mutual labels:  events
2018
Webend v4.5.26
Stars: ✭ 24 (-57.14%)
Mutual labels:  events
PyDREAM
Python Implementation of Decay Replay Mining (DREAM)
Stars: ✭ 22 (-60.71%)
Mutual labels:  events
commons.openshift.org
Repository for OpenShift Commons Community Site
Stars: ✭ 31 (-44.64%)
Mutual labels:  events
TOFileSystemObserver
A bullet-proof mechanism for detecting any changes made to the contents of a folder in iOS and macOS.
Stars: ✭ 35 (-37.5%)
Mutual labels:  filesystem
react-file-manager
A file manager built in ReactJs
Stars: ✭ 40 (-28.57%)
Mutual labels:  filesystem
ddlfs
Filesystem which represents Oracle Database objects as their DDL stored in .sql files
Stars: ✭ 31 (-44.64%)
Mutual labels:  filesystem
inotify-rs
Idiomatic inotify wrapper for the Rust programming language
Stars: ✭ 219 (+291.07%)
Mutual labels:  inotify

fswatch

Highlights

  • Single header file
  • Requires C++17 and std::filesystem
  • MIT License
  • For now, ONLY works in Linux - based on inotify

Quick Start

Simply include fswatch.hpp and you're good to go.

#include <fswatch.hpp>

To start watching files, create an fswatch object and provide a variadic list of directories to watch.

The constructor takes variadic arguments - Simply provide a list of directories to watch. This watcher will observe your home directory, /opt, /tmp and the current working directory.

auto watcher = fswatch("~", "/opt", "/tmp", ".");

try {
  watcher.start();
} catch (const std::runtime_error& error) {
  std::cout << error.what() << std::endl;
}

Register callbacks to events

To add callbacks to events, use the watcher.on(...) method like so:

watcher.on(fswatch::Event::FILE_CREATED, [](auto &event) {
  std::cout << "File created: " << event.path << std::endl;
});

You can register a single callback for multiple events like this:

watcher.on({ fswatch::Event::FILE_OPENED, fswatch::Event::FILE_CLOSED },
  [](auto &event) {
    if (event.type == fswatch::Event::FILE_OPENED)
      std::cout << "File opened: " << event.path << std::endl;
    else
      std::cout << "File closed: " << event.path << std::endl;
});

Here are the list of events that fswatch can handle:

File Events

Event Description
FILE_CREATED File created in watched directory
FILE_OPENED File opened in watched directory
FILE_MODIFIED File modified in watched directory (e.g., write, truncate)
FILE_CLOSED File closed in watched directory
FILE_DELETED File deleted from watched directory

Directory Events

Event Description
DIR_CREATED Directory created in watched directory
DIR_OPENED Directory opened in watched directory (e.g., when running ls)
DIR_MODIFIED Directory modified in watched directory
DIR_CLOSED Directory closed in watched directory
DIR_DELETED Directory deleted from watched directory

Todo

  1. Suppport Win32, FreeBSD, and OSX
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].