c# - FileSystemWatcher 检测 zip 文件

标签 c# filter zip file-watcher

我正在使用 FileSystemWatcher 类来检测在目录中创建的新文件。我正在创建 txt 和 zip 文件。它可以完美检测 txt 文件,但不能检测 zip 文件。我知道是否有人使用过此方法以及您的经验。

这是我的代码:

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);
    } 

谢谢!

最佳答案

如果将过滤器更改为 *.* 并将 zip 文件放入此后的目录中,它会执行任何操作吗?与 txt 文件相比,zip 文件是否很大?您是否尝试过 FileSystemWatcher 挑剔文件名区分大小写?

编辑:添加代码块

关于c# - FileSystemWatcher 检测 zip 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33676365/

相关文章:

filter - Hugo 从页面包中排除文件类型?

php - 使用 PHP 从 MySQL 文件创建 zip 存档

c# - 从加载的程序集中查找实现接口(interface)的对象 - 如何比较类型?

c# - 在单元测试期间显示 winform

python - 过滤二维 numpy 数组

python - 使用 FFT 计算滤波器 (b,a,x,zi)

python - 如何使用 python 检索 zip 文件中的目录?

javascript - 使用 JavaScript 将 blob 添加到 tar 并流式传输到服务器

c# - Numpy.NET 获取值

c# - 在 Entity Framework 核心中合并迁移