magicmonkey, on 1 Oct, 2008 - 12:25 PM, said:
Instead of using a timer to check there is a built in class in .NET named IO.FileSystemWatcher that can raise an event when ever a directory is changed or a file inside the directory is changed.
Now I am not sure what happens if you remove a thumb drive, but might be worth playing with this object as it might provide you with some powerful options.
Now I am not sure what happens if you remove a thumb drive, but might be worth playing with this object as it might provide you with some powerful options.
b.t.w. :
Fantastic,
but it CANT FIND IF THE DEVICE IS OFFLINE!!
look @ this
i've it from msdn
and changed it
Private Sub Run()
Dim args As String
args = FolderBrowserDialog1.SelectedPath
' Create a new FileSystemWatcher and set its properties.
Dim watcher As New FileSystemWatcher()
watcher.Path = args
' 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.
' Add event handlers.
AddHandler watcher.Changed, AddressOf onchanged
AddHandler watcher.Created, AddressOf onchanged
AddHandler watcher.Deleted, AddressOf onchanged
AddHandler watcher.Renamed, AddressOf OnRenamed
AddHandler watcher.Disposed, AddressOf Onoffline
AddHandler watcher.Error, AddressOf Onoffline
' Begin watching.
watcher.EnableRaisingEvents = True
' Wait for the user to quit the program.
label1.Text = "FileSystemWatcher() ONLINE"
End Sub
' Define the event handlers.
Private Sub onchanged(ByVal source As Object, ByVal e As FileSystemEventArgs)
' Specify what is done when a file is changed, created, or deleted.
label1.Text = "File: " & e.FullPath & " " & e.ChangeType
End Sub
Private Sub OnRenamed(ByVal source As Object, ByVal e As RenamedEventArgs)
' Specify what is done when a file is renamed.
label1.Text = "File: {0} renamed to {1}" & e.OldFullPath & e.FullPath
End Sub
Private Sub Onoffline(ByVal source As Object, ByVal e As ErrorEventArgs)
llabel1.Text = FolderBrowserDialog1.SelectedPath + " Is offline!"
End Sub
i've added this into my script and it redirects to other subs
it works fantastic, if a change a file @ my usb-stick,
then he reports everything
BUT
there is 1 problem
if i pull my stick out my pc
it says nothing
so i did this all for nothing or....?
This post has been edited by japie: 02 October 2008 - 10:17 AM

New Topic/Question
Reply





MultiQuote



|