Exemple #1
0
        public static void WatchDir(string inputDir, string fileRegEx, OnCreate OnCreated, OnRename OnRename = null)
        {
            FileSystemWatcher watcher = new FileSystemWatcher();

            watcher.Path = inputDir;
            //watcher.NotifyFilter = NotifyFilters.LastWrite;
            watcher.Filter = fileRegEx;
            var handler = new FileSystemEventHandler(OnCreated);

            watcher.IncludeSubdirectories = true;
            //watcher.Changed += handler;
            watcher.Created += handler;
            if (OnRename != null)
            {
                watcher.Renamed += new RenamedEventHandler(OnRename);
            }

            watcher.EnableRaisingEvents = true;
        }