Jaime Menendez Llana
Jaime Menendez Llana

Reputation: 473

FileSystemWatcher detection of zip files

I'm using FileSystemWatcher class to detect new files created in a directory. I'm creating txt and zip files. It's detects perfectly txt files but not the same with zip file. I know if anyone has worked with that and your experience.

Here is my code:

public void CreateWatcher(String path)
    {
        //Create a new FileSystemWatcher.
        FileSystemWatcher watcher = new FileSystemWatcher(path);

        watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
                     | NotifyFilters.FileName | NotifyFilters.DirectoryName;

        Thread.Sleep(2000);
        //Set the filter to all type of files
        watcher.Filter = "*.zip";

        //Subscribe to the Created event.
        watcher.Created += new FileSystemEventHandler(watcher_FileCreated);

        //Enable the FileSystemWatcher events.
        watcher.EnableRaisingEvents = true;
    }

    private void watcher_FileCreated(object sender, FileSystemEventArgs e)
    {
        logger.InfoFormat("New zip file created -> " + e.Name);
    } 

Thanks!

Upvotes: 2

Views: 773

Answers (1)

Oskari3000
Oskari3000

Reputation: 131

Does it do anything, if you change the filter to *.* and put the zip file to the directory after that? Is the zip file very large compared to the txt file? Have you tried that is the FileSystemWatcher picky with file names being case-sensitive?

edit: added code block

Upvotes: 2

Related Questions