Ezra
Veteran Member
Forgiveness is between them and God
Posts: 1960 Reputation: 31
37 / /
Joined: Mar 2003
|
RE: Check whether file exists
I made a little example:
code: Public Class Form1
Private File As String = "C:\DataFile.dat"
Private mywatcher As New IO.FileSystemWatcher 'Create new instance of FileSystemWatcher
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Check the first time if the File Exists
If System.IO.File.Exists(File) Then
mywatcher.Path = File 'Specify Path to File or Directory. Which ever you need
mywatcher.IncludeSubdirectories = False
mywatcher.NotifyFilter = IO.NotifyFilters.DirectoryName Or IO.NotifyFilters.FileName Or IO.NotifyFilters.LastWrite Or IO.NotifyFilters.Security
AddHandler mywatcher.Deleted, AddressOf OnDeleted 'Use intellisense to see what others are open to you
mywatcher.EnableRaisingEvents = True 'Start the process
End If
End Sub
Private Sub OnDeleted(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs)
If e.FullPath = File And e.ChangeType = IO.WatcherChangeTypes.Deleted Then
'FILE HAS BEEN REMOVED!!
End If
End Sub
End Class
WDZ implement auto code coloring
|
|