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
精彩评论