Skip to content

d2phap/FileWatcherEx

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FileWatcherEx for Windows

A wrapper of System.IO.FileSystemWatcher to standardize the events and avoid false change notifications. It has been being used in ImageGlass - A lightweight, versatile image viewer project.

This project is based on the VSCode FileWatcher: https://github.com/Microsoft/vscode-filewatcher-windows

Nuget

Resource links

Features

  • Standardizes the events of System.IO.FileSystemWatcher.
  • No false change notifications when a file system item is created, deleted, changed or renamed.
  • Supports .NET 6.0, 7.0.

Installation

Run the command:

# Nuget package
Install-Package FileWatcherEx

Usage

See Demo project for full details!

using FileWatcherEx;


var _fw = new FileSystemWatcherEx(@"C:\path\to\watch");

// event handlers
_fw.OnRenamed += FW_OnRenamed;
_fw.OnCreated += FW_OnCreated;
_fw.OnDeleted += FW_OnDeleted;
_fw.OnChanged += FW_OnChanged;
_fw.OnError += FW_OnError;

// thread-safe for event handlers
_fw.SynchronizingObject = this;

// start watching
_fw.Start();



void FW_OnRenamed(object sender, FileChangedEvent e)
{
  // do something here
}
...

License

MIT

Support this project

Thanks for your gratitude and finance help!