directory watcher ?

  • Thread starter Thread starter James
  • Start date Start date
J

James

..2003 have a filesystemwatcher ...

does it have a directorysystemwatcher ? What i need is to watch whether
directory is deleted ?

i assume filesystemwatcher delete method is for file, not directory.

Pls advise
 
does it watch a directory being DELETED ?

i thot filewatch only watch FILES within subdirectory.

More concern is DIRECTORY itself being deleted.
 
Hi,

Watch the directories parent for the directory being delete.
Simple example needs 2 buttons (btnDelete and btnAdd), a filesystemwatcher,
and listbox.

Imports System.IO


Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Directory.CreateDirectory("C:\Watch me")
FileSystemWatcher1.Path = "C:\Watch me"
FileSystemWatcher1.IncludeSubdirectories = True

End Sub

Private Sub FileSystemWatcher1_Created(ByVal sender As Object, ByVal e
As System.IO.FileSystemEventArgs) Handles FileSystemWatcher1.Created
Dim strOut As String

strOut = String.Format("Created {0}", e.Name)
ListBox1.Items.Add(strOut)
End Sub

Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAdd.Click
Try
Directory.CreateDirectory("C:\Watch me\Delete me")
Catch ex As Exception

End Try
End Sub

Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnDelete.Click
Try
Directory.Delete("C:\Watch me\Delete me")
Catch ex As Exception

End Try
End Sub

Private Sub FileSystemWatcher1_Deleted(ByVal sender As Object, ByVal e
As System.IO.FileSystemEventArgs) Handles FileSystemWatcher1.Deleted
Dim strOut As String

strOut = String.Format("Deleted {0}", e.Name)
ListBox1.Items.Add(strOut)

End Sub
End Class


Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top