2013-09-23 17 views
1

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

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

如果你想要做的事已创建再一个特定的文件,当您需要使用不同的事件处理程序(创建) – Steve

回答

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 
+0

@Tim怎么样,如果我读文本姓名(或名称)?我有表满的文件名,我认为这会工作,但没有运气:'如果e.name.toupper.contains(textbox1.text)然后' – Jedi

相关问题