是否可以使用带有if语句的filesystemwatcher来验证文件夹中的更改? [英] Is it possible to use filesystemwatcher with a if statement to verify the change in a folder?
本文介绍了是否可以使用带有if语句的filesystemwatcher来验证文件夹中的更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建一个C#控制台应用程序,它使用filesystemwatcher检查文件夹中文件的创建。
I'm creating a C# console application which checks for the creation of a file in a folder using filesystemwatcher.
FileSystemWatcher fileChecker = new FileSystemWatcher();
fileChecker.Path = "C:\";
fileChecker.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
fileChecker.Filter = "*.txt";
fileChecker.Changed += new FileSystemEventHandler(OnChanged);
fileChecker.Created += new FileSystemEventHandler(OnChanged);
// Begin watching.
fileChecker.EnableRaisingEvents = true;
//我的添加类似于
//my addition would be something like
if(filechecker.created != true)
{
// in this section I'm expecting a change in the folder
}
else
{
// do nothing
}
我尝试过:
FileSystemWatcher Class(System.IO) )| Microsoft Docs [ ^ ]
推荐答案
您已声明fileChecker.Created;
作为委托
而非bool
,因此您不能使用该if语句。
You have declaredfileChecker.Created;
as adelegate
not abool
, so you cannot use that if statement.
这篇关于是否可以使用带有if语句的filesystemwatcher来验证文件夹中的更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文