FileSystemWatcher Help. 
Author Message
 FileSystemWatcher Help.

I'm trying to create a very simple app that just sits there running and
wathcing for file creation... when there is a file created I would like it
to fire another function in another module... This is what I have so far...
it compiles fine, but it basically just runs once, checks for a file then
exits... how do I set it up to continuously run??

Imports System.IO
Imports System.IO.FileSystemWatcher

Module subMain
    Sub Main()

        Dim strpath As String = "c:\tmp\"
        'test for path or the rest of the app will puke all over

        If Not Directory.Exists(strpath) Then
            Directory.CreateDirectory(strpath)
        End If

        'start watching for files being created
        Dim Watcher As New FileSystemWatcher()
        Watcher.Path = strpath
        Watcher.Filter = "*.htm"
        Watcher.Filter = "*.txt"
        Watcher.NotifyFilter = NotifyFilters.LastWrite
        AddHandler Watcher.Changed, AddressOf OnChanged
        Watcher.EnableRaisingEvents = True
    End Sub

    ' event handlers.
    Sub OnChanged(ByVal source As Object, ByVal e As FileSystemEventArgs)
        'call other function(s) here...
        Console.WriteLine("File: " & e.FullPath & " " & e.ChangeType)
    End Sub

End Module



Sun, 11 Sep 2005 23:56:57 GMT  
 FileSystemWatcher Help.
Answered myself:

        'start watching for files being created
        Dim Watcher As New FileSystemWatcher()
        Watcher.Path = strpath
        Watcher.Filter = "*.htm" Or "*.htm"
        Watcher.NotifyFilter = NotifyFilters.LastWrite Or
NotifyFilters.CreationTime
        AddHandler Watcher.Changed, AddressOf OnChanged
        Watcher.EnableRaisingEvents = True

        ' Wait for the user to quit the program.
        Console.WriteLine("Press 'q' to quit.")
        While Chr(Console.Read()) <> "q"c
        End While


Quote:
> I'm trying to create a very simple app that just sits there running and
> wathcing for file creation... when there is a file created I would like it
> to fire another function in another module... This is what I have so
far...
> it compiles fine, but it basically just runs once, checks for a file then
> exits... how do I set it up to continuously run??

> Imports System.IO
> Imports System.IO.FileSystemWatcher

> Module subMain
>     Sub Main()

>         Dim strpath As String = "c:\tmp\"
>         'test for path or the rest of the app will puke all over

>         If Not Directory.Exists(strpath) Then
>             Directory.CreateDirectory(strpath)
>         End If

>         'start watching for files being created
>         Dim Watcher As New FileSystemWatcher()
>         Watcher.Path = strpath
>         Watcher.Filter = "*.htm"
>         Watcher.Filter = "*.txt"
>         Watcher.NotifyFilter = NotifyFilters.LastWrite
>         AddHandler Watcher.Changed, AddressOf OnChanged
>         Watcher.EnableRaisingEvents = True
>     End Sub

>     ' event handlers.
>     Sub OnChanged(ByVal source As Object, ByVal e As FileSystemEventArgs)
>         'call other function(s) here...
>         Console.WriteLine("File: " & e.FullPath & " " & e.ChangeType)
>     End Sub

> End Module



Mon, 12 Sep 2005 00:03:09 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. FileSystemWatcher Help !!!

2. Threading and the FileSystemWatcher WatchForChanges method

3. FileSystemWatcher - capture who changed the file?

4. newbie question about FileSystemWatcher

5. FileSystemWatcher Path / Directory size

6. does FileSystemWatcher class work with Windows 98 ??

7. FileSystemWatcher

8. Get Name Of FileSystemWatcher

9. FileSystemWatcher name by sender

10. FileSystemWatcher Service and network drives

11. FileSystemWatcher

12. FileSystemWatcher Issue with UNC

 

 
Powered by phpBB® Forum Software