如何在C#中使用Filewatcher

编程入门 行业动态 更新时间:2024-10-25 18:28:20
本文介绍了如何在C#中使用Filewatcher的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经为filewatcher创建了一个程序,但是虽然我在window应用程序中理解了它,但是却无法在控制台应用程序中理解它.

I have created a program for filewatcher but not able to understand it in console application though i understood it in window application.

namespace fsw_watcher { class Program { static void Main(string[] args) { FileSystemWatcher fsw = new FileSystemWatcher (Environment.GetEnvironmentVariable("USERPROFILE")); fsw.IncludeSubdirectories = true; fsw.NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite; fsw.Created += new FileSystemEventHandler(fsw_created); fsw.Deleted += new FileSystemEventHandler(fsw_deleted); fsw.Renamed += new RenamedEventHandler(fsw_Renamed); fsw.Changed += new FileSystemEventHandler(fsw_Changed); fsw.EnableRaisingEvents = true; Console.WriteLine("Press a key to end the program."); Console.ReadKey(); } static void fsw_created(object sender, FileSystemEventArgs e) { Console.WriteLine("created"+ e.FullPath); } static void fsw_deleted(object sender, FileSystemEventArgs e) { Console.WriteLine("deleted" + e.FullPath); } static void fsw_Changed(object sender, FileSystemEventArgs e) { Console.WriteLine(e.ChangeType + ": " + e.FullPath); } static void fsw_Renamed(object sender, RenamedEventArgs e) { Console.WriteLine(e.ChangeType + " from " + e.OldFullPath + " to " + e.Name); } } }

以窗口形式,我能够给出路径并可以在那里监视,但是在这里我无法找到给出路径的位置. 因此,如果有人可以帮助我. 谢谢 问候

in window form i was able to give path and could monitor there but here i am not able to locate where to give path. So if anybody could help me in this . thanks regards

推荐答案

C#中的File Watcher Windows [ ^ ] www.c-sharpcorner/uploadfile/puranindia/filesystemwatcher-in -C-Sharp/ [ ^ ] File Watcher Windows in C#[^] www.c-sharpcorner/uploadfile/puranindia/filesystemwatcher-in-C-Sharp/[^]

更多推荐

如何在C#中使用Filewatcher

本文发布于:2023-11-03 06:42:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1554480.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   Filewatcher

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!