zoukankan      html  css  js  c++  java
  • C#监听文件

    //全局变量 

    public static FileSystemWatcher Watcher;

           /// <summary>
            /// 设置监听配置
            /// </summary>
            /// <returns>ture/false</returns>
            public static Boolean SetMonitorFile()
            {
                try
                {
                    Watcher = new FileSystemWatcher();
                    Watcher.Filter = "*.txt";
                    Watcher.Path = "d:\"; //路径
                    Watcher.NotifyFilter = NotifyFilters.Size; //文件大小改变
                    //文件改变事件
                    Watcher.Changed += new FileSystemEventHandler(Watcher_Changed); ;
                    //文件创建事件       
                    Watcher.Created += new FileSystemEventHandler(Watcher_Created);
                    //文件删除事件
                    Watcher.Deleted += new FileSystemEventHandler(Watcher_Deleted);
                    //文件重命名事件
                    Watcher.Renamed += new RenamedEventHandler(Watcher_Renamed);
                    //设置监听子目录
                    Watcher.IncludeSubdirectories = false;
                    //开始进行监听(其实此处是标示是否进行事件监听和抛出)
                    Watcher.EnableRaisingEvents = true;
                    //watcher.EndInit();
                    return true;
                }
                catch (Exception ex)
                {
                    return false;
                }

            }

  • 相关阅读:
    Flume 读取实时更新的日志文件
    一些关于Flume收集日志的资料
    Java Pattern Matcher 正则表达式需要转义的字符
    多播 & multicast
    branch prediction
    一时紧张简单题都没做好,哈
    海量数据求中位数
    继续过Hard题目.0207
    压力工具代码及epoll使用
    C++里面mutable的作用
  • 原文地址:https://www.cnblogs.com/-lxl/p/4843853.html
Copyright © 2011-2022 走看看