How to filter using filesystem watcher in vb.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • visweswaran2830
    New Member
    • Nov 2009
    • 92

    #1

    How to filter using filesystem watcher in vb.net

    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
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

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

    Comment

    • !NoItAll
      Contributor
      • May 2006
      • 297

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

      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 sExt
      This seems reasonable to me - but only if you are not watching the entire spectrum of files on a system.

      Comment

      Working...