Search code examples
c#.netwinformsfile-iofilesystemwatcher

FileSystemWatcher Filter - Detect Zipped Files?


I'm using a FileSystemWatcher to detect that a text file is created in directory A and subsequently created in directory B.

The issue I'm having is, the process which moves the file from directory A to directory B also zips the file up, changing the filename from say "999_XXX_001.txt" to "999_XXX_001.txt.zip"

Three problems with this;

1) I can no longer open and read the file to analyse the contents

2) The filename has changed

3) The FileSystemWatcher appears to only support a single extension

Solution

Using two watchers, one for ".zip" and one for ".txt", I'm removing the .zip and comparing filenames because moved files no longer exist to be compared byte-for-byte.. I guess the real question here was how can I use the watcher to detect ".txt.zip" as an extension!


Solution

    1. Why? You would have to wait until the process has finished its zipping magic and afterwards you can open the zip file with your framework of choice
    2. Why is it a problem itself that the filename has changed?
    3. No, the file watcher will detect any change of all files within the given directory

    But maybe it is better to describe what you actually try to achieve here. There is probably a better solution to what you actually need.