开发者

Monitoring File Changes in C# [duplicate]

This question already has answers here: Notification when a file changes? (3 answers) Closed 6 years ago.

I'm using C# for a mini project of mine, I am trying to monitor files that are changed, Deleted, And/or created. And exp开发者_运维百科ort that to a file. But I am not quite sure how to monitor files. Any ideas?


You can use the FileSystemWatcher class to monitor file creation, modifications, deletions and renames.

You have the following events available:

  • Changed
  • Created
  • Deleted
  • Renamed


you can only monitor one Directory with FSW, if you want more you may have to make multiple instances of FSW. It monitors the directory not the file; if the file is moved (changed+created; changed+renamed) then you need another FSW for that destination folder.


Yep, FileSystemWatcher will do this. Be careful what you wish for, because this thing watches everything!

Have a look here, it explains how you it can fire multiple events (eg when a file is moved, firing an OnChange and OnCreate

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜