Skip to content

Commit d0b669d

Browse files
authored
Merge pull request #4 from PhantomGamers/filters
Expose FileSystemWatcher.Filters Property
2 parents 8f92d45 + 1cac07f commit d0b669d

1 file changed

Lines changed: 25 additions & 3 deletions

File tree

Source/FileWatcherEx/FileSystemWatcherEx.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,27 @@ public class FileSystemWatcherEx : IDisposable
3131
public string FolderPath { get; set; } = "";
3232

3333

34+
/// <summary>
35+
/// The collection of all the filters used to determine what files are monitored in a directory.
36+
/// </summary>
37+
public System.Collections.ObjectModel.Collection<string> Filters { get; } = new();
38+
39+
3440
/// <summary>
3541
/// Filter string used for determining what files are monitored in a directory
3642
/// </summary>
37-
public string Filter { get; set; } = "*.*";
43+
public string Filter
44+
{
45+
get
46+
{
47+
return Filters.Count == 0 ? "*" : Filters[0];
48+
}
49+
set
50+
{
51+
Filters.Clear();
52+
Filters.Add(value);
53+
}
54+
}
3855

3956

4057
/// <summary>
@@ -213,7 +230,12 @@ void onError(ErrorEventArgs e)
213230
_watcher = new FileWatcher();
214231

215232
_fsw = _watcher.Create(FolderPath, onEvent, onError);
216-
_fsw.Filter = Filter;
233+
234+
foreach (var filter in Filters)
235+
{
236+
_fsw.Filters.Add(filter);
237+
}
238+
217239
_fsw.NotifyFilter = NotifyFilter;
218240
_fsw.IncludeSubdirectories = IncludeSubdirectories;
219241
_fsw.SynchronizingObject = SynchronizingObject;
@@ -260,7 +282,7 @@ public void Stop()
260282
// stop the thread
261283
_cancelSource.Cancel();
262284
}
263-
285+
264286

265287

266288
/// <summary>

0 commit comments

Comments
 (0)