关闭

C#中文件监视的操作

标签: 文件监视C#
396人阅读 评论(0) 收藏 举报
分类:

1.            监视文件的操作用类FileSystemWatcher

   FileSystemWatcher fsw = new FileSystemWatcher();

        private void Form1_Load(object sender, EventArgs e)

        {

            //¨??线?¨¬¨¦°?¨´Á¡Â?t

            Control.CheckForIllegalCrossThreadCalls = false;

            fsw.Path = @"E:\";

            //¨¤º¨®?tÌ?¤¨¤¨ª

            fsw.Filter = "*.txt";

            //¨¤º¨®Á¨®?tD

            fsw.IncludeSubdirectories = true;

            //¨¤º¨®?tä¡ä¡§

            //created  deleted  renamed changed

            fsw.Created += new FileSystemEventHandler(fsw_Created);

            fsw.Changed += new FileSystemEventHandler(fsw_Changed);

            fsw.Deleted += new FileSystemEventHandler(fsw_Deleted);

            //?®?¨¤º¨®

            fsw.EnableRaisingEvents = true;

        }

 

        void fsw_Deleted(object sender, FileSystemEventArgs e)

        {

            listBox1.Items.Add(e.Name+"--"+e.ChangeType);

           

        }

 

        void fsw_Changed(object sender, FileSystemEventArgs e)

        {

            listBox1.Items.Add(e.Name + "--" + e.ChangeType);

            fsw.EnableRaisingEvents = false;

            fsw.EnableRaisingEvents = true;

        }

 

        void fsw_Created(object sender, FileSystemEventArgs e)

        {

            listBox1.Items.Add(e.Name + "--" + e.ChangeType);

        }

 

 

 

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:12267次
    • 积分:304
    • 等级:
    • 排名:千里之外
    • 原创:16篇
    • 转载:5篇
    • 译文:1篇
    • 评论:0条
    文章分类