C#中文件监视的操作

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);

        }

 

 

 

阅读更多
文章标签: 文件监视 C#
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

C#中文件监视的操作

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭