guoguogis

  :: :: 博问 :: 闪存 :: 新随笔 :: :: :: 管理 ::

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace FileInfo
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)//浏览文件夹
        {
            if(this.folderBrowserDialog1.ShowDialog()==DialogResult.OK)
            {
                if(this.folderBrowserDialog1.SelectedPath.Trim()!="")
                {
                    this.textBox1.Text = this.folderBrowserDialog1.SelectedPath;
                }

            }
        }

        private void button2_Click(object sender, EventArgs e)//确定监视文件夹
        {
            if (Directory.Exists(this.textBox1.Text) == false)
            {
                MessageBox.Show("选择的不是一个文件夹", "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                this.fileSystemWatcher1.Path = this.textBox1.Text;
                this.richTextBox1.Text = "";//当监视其他文件夹时,清除记录
                MessageBox.Show("文件夹"+this.textBox1.Text+"已经处于监视状态!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
            }
        }
        //fileSystemWatcher的自身事件:
        private void fileSystemWatcher1_Changed(object sender, FileSystemEventArgs e)
        {
            this.richTextBox1.Text+=e.FullPath.ToString()+"已经改变!"+'\n';
        }

        private void fileSystemWatcher1_Created(object sender, FileSystemEventArgs e)
        {
            this.richTextBox1.Text+="创建文件:"+e.FullPath.ToString()+'\n';
        }

        private void fileSystemWatcher1_Deleted(object sender, FileSystemEventArgs e)
        {
            this.richTextBox1.Text += "删除文件" + e.FullPath.ToString()+'\n';
        }

        private void fileSystemWatcher1_Renamed(object sender, RenamedEventArgs e)
        {
            this.richTextBox1.Text+="重命名文件:"+e.FullPath.ToString()+'\n';
        }
    }
}


posted on 2009-08-28 19:23  guoguogis  阅读(364)  评论(0编辑  收藏  举报