Dim allDrives() As DriveInfo = DriveInfo.GetDrives() Dim d As DriveInfo For Each d In allDrives If d.IsReady = True Then ' Créé un nouveau FileSystemWatcher Dim watcher As New FileSystemWatcher() ' Path à surveiller MsgBox(d.RootDirectory.FullName) watcher.Path = d.RootDirectory.FullName ' Les opérations que l'on surveille watcher.NotifyFilter = (NotifyFilters.LastAccess Or NotifyFilters.LastWrite Or NotifyFilters.FileName Or NotifyFilters.DirectoryName) ' Les types de fichier que l'on surveille ' watcher.Filter = "*.txt" ' On surveille même les sous dossiers watcher.IncludeSubdirectories = True ' Ajout des événements AddHandler watcher.Changed, AddressOf OnChanged AddHandler watcher.Created, AddressOf OnChanged AddHandler watcher.Deleted, AddressOf OnChanged AddHandler watcher.Renamed, AddressOf OnRenamed ' On commence le watcher watcher.EnableRaisingEvents = True End If Next
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionDim FSO = CreateObject("Scripting.FileSystemObject") For Each Drv In FSO.Drives If Drv.IsReady Then ' Créé un nouveau FileSystemWatcher Dim watcher As New FileSystemWatcher() ' Path à surveiller watcher.Path = Drv.Path ' Les opérations que l'on surveille watcher.NotifyFilter = (NotifyFilters.LastAccess Or NotifyFilters.LastWrite Or NotifyFilters.FileName Or NotifyFilters.DirectoryName) ' Les types de fichier que l'on surveille ' watcher.Filter = "*.txt" ' On surveille même les sous dossiers watcher.IncludeSubdirectories = True ' Ajout des événements AddHandler watcher.Changed, AddressOf OnChanged AddHandler watcher.Created, AddressOf OnChanged AddHandler watcher.Deleted, AddressOf OnChanged AddHandler watcher.Renamed, AddressOf OnRenamed ' On commence le watcher watcher.EnableRaisingEvents = True End If Next
For Each drv As IO.DriveInfo In IO.DriveInfo.GetDrives