2013-09-23 5 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

@ 팀 어떻게 텍스트 상자에서 이름 (들)을 읽으면? 나는 전체 목록을 가지고에 대해 파일 이름과 나는 이것이 잘 될 것이라고 생각했지만 운이 없다 :'e.name.toupper.contains (textbox1.text) then then' – Jedi

관련 문제