Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I watch a file system directory to see when files are added to it?

In c# winforms application, I want to choose a directory from network and after that, when any body put a file in it, I want to see a message such as "A file added."

for example I can get filepaths.

string[] filePaths = Directory.GetFiles(@"c:\MyDir\", "*.bmp");

should I run this code 5 minutes later and should I check the differences?

like image 868
Göktürk Solmaz Avatar asked Dec 28 '25 02:12

Göktürk Solmaz


1 Answers

You could use the FileSystemWatcher class and subscribe for different events happening on the file system such as files and folders being created, deleted, modified, ...

like image 77
Darin Dimitrov Avatar answered Dec 30 '25 17:12

Darin Dimitrov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!