C # File Monitor simple example source code
Private void btn_FileWatcher_Click (object sender, EventArgs e)
{
FileSystemWatcher k8watcher = new FileSystemWatcher ();
K8watcher. Path = "d: \ K8team ";
K8watcher. IncludeSubdirectories = true;
K8watcher. EnableRaisingEvents = true;
K8watcher. SynchronizingObject = this;
K8watcher. Created + = new FileSystemEventHandler (k8fileCreated );
K8watcher. Changed + = new FileSystemEventHandler (k8fileChanged );
K8watcher. Renamed + = new RenamedEventHandler (k8fileRenamed );
K8watcher. Deleted + = new FileSystemEventHandler (k8fileDeleted );
}
Public void k8fileCreated (object sender, FileSystemEventArgs e)
{
String log = string. format (e. changeType + ": {0} -- Time: {1} \ r \ n", e. fullPath, DateTime. now. toString ());
Txt_Relust.AppendText (log );
}
Public void k8fileChanged (object sender, FileSystemEventArgs e)
{
String log = string. format (e. changeType + ": {0} -- Time: {1} \ r \ n", e. fullPath, DateTime. now. toString ());
Txt_Relust.AppendText (log );
}
Public void k8fileDeleted (object sender, FileSystemEventArgs e)
{
String log = string. format (e. changeType + ": {0} -- Time: {1} \ r \ n", e. fullPath, DateTime. now. toString ());
Txt_Relust.AppendText (log );
}
Public void k8fileRenamed (object sender, FileSystemEventArgs e)
{
String log = string. format (e. changeType + ": {0} -- Time: {1} \ r \ n", e. fullPath, DateTime. now. toString ());
Txt_Relust.AppendText (log );
}