Click here to Skip to main content
12,395,645 members (53,101 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB VB.NET
I have asked this question and do not mean to spam in any way to ask again but since then I have made an attempt to figure this thing out. To refresh my question I am looking to monitor all hard drives directories and sub directories with Filesystem watcher. Thus far i have this code which does not seem to monitor any drive


Imports System.IO
Public Class Form1
    Private _watchers As FileSystemWatcher()
    Private Sub OnStart(args As String())
        Dim drives As String() = Environment.GetLogicalDrives()
        _watchers = New FileSystemWatcher(drives.Length - 1) {}
        Dim i As Integer = 0
        For Each strDrive As String In drives
            'Check if the drive is ready to be used 
            Dim df As New DriveInfo(strDrive)
            If Not df.IsReady Then
                Continue For
            End If
            Dim _watcher As New FileSystemWatcher()
            _watcher.Path = strDrive
            AddHandler _watcher.Changed, AddressOf OnChanged
            AddHandler _watcher.Created, AddressOf OnChanged
            AddHandler _watcher.Deleted, AddressOf OnChanged
            AddHandler _watcher.Renamed, AddressOf OnRenamed
        Next
    End Sub
    Private Sub OnChanged(source As Object, e As FileSystemEventArgs)
        ' Specify what is done when a file is changed, created, or deleted.
        ListBox1.Items.Add("File: " & e.FullPath & " " & e.ChangeType)
    End Sub
    Private Sub OnRenamed(ByVal sender As Object, ByVal e As RenamedEventArgs)
        ' Specify what is done when a file is renamed.
        ListBox1.Items.Add("File: " & e.FullPath & " " & e.ChangeType)
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        FolderWatcherTest.EnableRaisingEvents = True
    End Sub
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        FolderWatcherTest.EnableRaisingEvents = False
    End Sub
End Class


Some of this code has been converted from C# to vb.net
what do i need to correct or add to this to get the desired result?

thank you in advance!!
Posted 12-Jan-13 19:29pm
Dale 20121.8K
Comments
Sandeep Mewara 13-Jan-13 2:12am
   
You get errors? Wheres the C# source?
VitorHugoGarcia 14-Jan-13 4:23am
   
I guess you should set :
.Filter = "*.*" 'for all file types
.IncludeSubdirectories = true ' or false depending on what you want to achive
.EnableRaisingEvents = true
for each of your fs objects.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 13 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100