FileSystemWatcher() 的文件过滤器

File Filter for FileSystemWatcher()

我想弄明白,如何只观看特定方式的文件: 例如

  1. 文件夹将填充名称相同但扩展名不同(.zip、.another)的文件
  2. 该文件将有一个特定的名称,例如ASK_QUESTION_VERSION_XXXXXXX.zip,其中 XXXXXX 将发生变化。
  3. 因为文件夹将填充不同的文件,例如DIFFERENT_FILE_XXXXXX.zip,命名相似,我只想看第一个文件被放置。

如何在此处过滤?下面是代码:

 public void watch(List<string> servicesInvolved, int timeout)
    {
        watcher.Path = sourcePath;
        watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName
                               | NotifyFilters.DirectoryName | NotifyFilters.CreationTime;
        watcher.Filter = "*.*";
        // The below did not work, e.g. compilation errors, could not add two filters. 
        //watcher.Filter.Add("*.zip");
        //watcher.Filters.Add("FileName*");

        watcher.Created += (sender, e) => OnChanged(sender, e,  servicesInvolved, timeout);
        watcher.EnableRaisingEvents = true;

    }

根据@CodeCaster watcher.Filter = MyFolder*Name*.zip;

,这在某种程度上是一个简单的答案