FileSystemWatcher Created event not firing for files that has been moved from zip archive

Yosif Chumpov 21 Reputation points
2022-03-31T20:28:00.977+00:00

I have a very simple scenario where FSW just doesn't work. I use code like that to setup the watcher:

private FileSystemWatcher watcher = new FileSystemWatcher(@"folderToListenForChanges"))

private void Listen(){ 
            watcher.IncludeSubdirectories = true;
            watcher.NotifyFilter =
                NotifyFilters.FileName |
                NotifyFilters.DirectoryName |
                NotifyFilters.LastWrite |
                NotifyFilters.Security |
                NotifyFilters.CreationTime |
                NotifyFilters.LastAccess |
                NotifyFilters.Attributes |
                NotifyFilters.Size;
            watcher.Filter = "*.*";
            watcher.Created += Watcher_Created;
            watcher.Renamed += Watcher_Renamed;
            watcher.Deleted += Watcher_Deleted;
            watcher.Error += Watcher_Error;
            watcher.Changed += Watcher_Changed;

            watcher.EnableRaisingEvents = true;
        }
    }

Let say that there is a zip archive containing single file and folder similar to this one:

Some Dir \ some file.txt

The zip archive is outside "folderToListenForChanges". The thing is that when I open this archive with 7zip and use drag&drop to copy the "Some Dir" folder of the archive into the "folderToListenForChanges", FSW fire event only for directory creation but NOT for file creation. Any ideas?

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,264 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Valera_ 0 Reputation points
    2024-03-30T15:31:59.71+00:00

    I have more global issue under win10:
    without NotifyFilters.Security - does not work for Blazor Web App!!

    https://learn.microsoft.com/en-us/dotnet/api/system.io.filesystemwatcher?view=net-8.0
    watcher.NotifyFilter = NotifyFilters.Attributes

    | NotifyFilters.CreationTime

                     | NotifyFilters.DirectoryName
    
                     | NotifyFilters.FileName
    
                     | NotifyFilters.LastAccess
    
                     | NotifyFilters.LastWrite
    
                     | NotifyFilters.Security
    
                     | NotifyFilters.Size;
    

    worked, but if you remove | NotifyFilters.Security - it does not work.

    Is there any information on MSDN about this??

    0 comments No comments