VB.NET2005

Imports System.IO.FileSystemWatcher
Imports System.IO

Class App1

Public Shared Sub Main()
Console.WriteLine("Show current file status")
Console.WriteLine("=========================")

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Create a new FileSystemWatcher and set its properties.
Dim watcher As New FileSystemWatcher()
watcher.Path = "C:\test" 'args(1)
' Watch for changes in LastAccess and LastWrite times, and
' the renaming of files or directories.
watcher.NotifyFilter = (NotifyFilters.LastAccess Or NotifyFilters.LastWrite Or NotifyFilters.FileName Or NotifyFilters.DirectoryName)
' Only watch text files.
watcher.Filter = "*.txt"
' Add event handlers.
AddHandler watcher.Changed, AddressOf OnChanged
AddHandler watcher.Created, AddressOf OnChanged
AddHandler watcher.Deleted, AddressOf OnChanged
AddHandler watcher.Renamed, AddressOf OnRenamed

' Begin watching.
watcher.EnableRaisingEvents = True

' Wait for the user to quit the program.
Console.WriteLine("Press any 'Key' to quit....")

Console.ReadLine()

End Sub


' Define the event handlers.
Private Shared Sub OnChanged(ByVal source As Object, ByVal e As FileSystemEventArgs)
Dim m As String
' Specify what is done when a file is changed, created, or deleted.
m = "File: " & e.FullPath & " " & e.ChangeType

Console.WriteLine(m)
End Sub

Private Shared Sub OnRenamed(ByVal source As Object, ByVal e As RenamedEventArgs)
Dim m As String
' Specify what is done when a file is renamed.
m = "File: {0} renamed to {1}"
Console.WriteLine(m, e.OldFullPath, e.FullPath)
End Sub


End Class



Re: Visual Basic Express Edition How I can change the following example code to use a form ListBox, not Console??

BadButBit

hi,

listboxes aren't a great mystery(at least getting started isn't) ... paste a list box onto your form and call it whatever e.g. lstMyFirstListBox. then if you ever need to initialize it :

lstMyFirstListBox.items.clear

after that... whenever you want to add something

lstMyFirstListBox.items.add("this is the text I want to see" & intCounter.toString)

in the left combo box above your code you can select lstMyFirstListBox and in the right combo box choose one of the events like 'click' for example... and a program subroutine 'stub' will be automatically written for you... write your code there for that even. and you're on your way....

BadButBit





Re: Visual Basic Express Edition How I can change the following example code to use a form ListBox, not Console??

VB.NET2005

Hi

That is not to easy, is not the problem to use List Boxes it is a Cross-thread operation problem...

using Console it is not problem it is when you try to output it to any Form base control (label, text box, etc.)

Any idea