开发者

Ignoring a certain file type in a .net "filter"

开发者 https://www.devze.com 2022-12-11 15:40 出处:网络
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

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!


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 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号