如果使用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
如果你不理解,我会解释。
答案 0 :(得分: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