忽略.net“过滤器”中的特定文件类型
我制作了一个使用 filesystemwatcher 组件的程序,但它似乎绝对记录了所做的每一个更改,并且我想将其设置为忽略某些文件类型。如何设置过滤器以忽略某些类型?例如,.LOG 文件。我不希望它告诉我该文件会更新,因为它实际上每秒都会更新一次。
更好的是,有什么办法让它忽略某些文件夹吗?
感谢您的帮助!
I made a program which uses a filesystemwatcher component, but it seems to record absolutely EVERY change made, and I want to set it to ignore some file types. How can I set the filter to ignore certain types? For example, .LOG files. I don't want it telling me that that file updates, cause it does it every second practically.
Even better, is there any way to make it ignore some folders?
Thanks for the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您不能仅使用 排除某些文件类型过滤。
我建议您在每个处理程序的开头添加一个测试,以跳过对您不想处理的文件的任何处理。
FileSystemWatcher 监视文件夹中所有文件和文件夹的更改,包括子目录中的文件和文件夹。例如,如果您想忽略对日志文件的更改,则将日志目录移动到不在您正在监视的路径内的文件夹可能是更好的选择。
I don't think you can exclude certain file types using only a Filter.
I would suggest that you add a test at the start of each of your handlers to skip any processing of files which you don't want to process.
The FileSystemWatcher watches for changes to all files and folders within a folder, including files and folders within sub-directories. If you want to ignore changes to your log files, for example, it might be a better option to move the log directory to a folder which is not within the path that you are watching.
MSDN 有详细信息。 FileSystemWatcher 上有一个 Filter 属性可以用来仅包含那些您想要通知的文件。
MSDN has the details. There is a Filter property on the FileSystemWatcher that you can use to include only those files for which you want notifications.