Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Directory Listener in C#

Tags:

c#

Is there any library for listening a directory? I mean I have a directory and I want to be informed of any changes in it.

For example: when some files are deleted or created in the directory, I want to be informed. I don't want to use a timer and check the directory manually to detect any changes.

like image 796
Mustafa Ekici Avatar asked Nov 20 '11 16:11

Mustafa Ekici


People also ask

What is directory in C?

The directory holds all that information, such as the file's physical location, its name, timestamps, permissions, and other trivia. These details are accessible when you use the proper C language functions. To access a directory, use the opendir() function. It's prototyped in the dirent.

How FileSystemWatcher works?

It watches a file or a directory in your system for changes and triggers events when changes occur. In order for the FileSystemWatcher to work, you should specify a directory that needs to be monitored. The FileSystemWatcher raises the following events when changes occur to a directory that it is monitoring.

What is FileSystemWatcher in c#?

C# FileSystemWatcher acts as a watchdog for file system changes and raises an event when a change occurs. You must specify a directory to be monitored. The class can monitor changes to subdirectories and files within the specified directory.

What is a file watcher?

File Watcher is an IntelliJ IDEA tool that allows you to automatically run a command-line tool like compilers, formatters, or linters when you change or save a file in the IDE.

What is a directory in memory?

Memory directory contains files of the whole system. All the device information, process running indata or system related information are stored in this directory. Memory directory contains the following directories. /dev.


1 Answers

Sounds like you're looking for FileSystemWatcher. See the documentation for a complete example.

like image 129
Jon Skeet Avatar answered Oct 15 '22 15:10

Jon Skeet