HI, I Want to filter a file using filesystem watcher. In that, I want to filter more than one type. Let it be, *.exe, *.java....... How can I achieve this
How to filter using filesystem watcher in vb.net
Collapse
X
-
Tags: None
-
I'm reasonably certain you'll need to set up one FileSystemWatch er for each extension.
There should be no problem pointing them all to the same method handler if you need to. The arguments of the event include the file name, so you can use a Switch construct to take action dependent on the extension from there. -
Maybe this is a stupid suggestion, but depending on what you are watching you could set the filter to *.* and then process only the files you want in the function - returning gracefully for any file that does not match your criteria.
This isn't practical if you are watching the entire file system, but if you are looking at a single folder and its subs then this is a reasonable approach.
This seems reasonable to me - but only if you are not watching the entire spectrum of files on a system.Code:Friend Sub MyTriggeredFunction(ByVal sFile as String) Static sExtensions() as String = {".txt", ".csv", ".doc"} For each sExt as String in sExtensions If System.IO.Path.GetExtension(sFile).ToLower.Contains(sExt) then 'process the file Return End if Next sExtComment
Comment