1

如果使用 FileSystemWatcher 在例如“C:\”中创建具有指定名称的文件,是否有办法执行操作?

Private Sub FileSystemWatcher1_changed(ByVal sender As System.Object, ByVal e As System.IO.FileSystemEventArgs) Handles FileSystemWatcher1.Changed
    If 
         'really don't know what to put here
    End If
End Sub

如果您不明白,我会解释。

4

1 回答 1

3

假设您已经准备好FileSystemWatcher1使用这些属性

Dim FileSystemWatcher1 = New FileSystemWatcher()
FileSystemWatcher1.Path = "C:\"
FileSystemWatcher1.Filter = "*.*"
AddHandler FileSystemWatcher1.Created, AddressOf OnCreated
FileSystemWatcher1.EnableRaisingEvents = True
.....

然后,您可以像上面那样编写事件处理程序,并查看FileSystemEventArgs传递给事件处理程序的参数的属性,以了解所创建文件的确切名称。

Private Shared Sub OnCreated(source As Object, e As FileSystemEventArgs)
    If e.Name.ToUpper() == "MYTEXTFILE.TXT" then
        ' do you code here '
    End If
End Sub
于 2013-09-23T15:19:03.980 回答