Me.FileSystemWatcher1.EnableRaisingEvents = True Me.FileSystemWatcher1.Filter = "*.txt" Me.FileSystemWatcher1.NotifyFilter = System.IO.NotifyFilters.LastWrite Me.FileSystemWatcher1.Path = "D:\Data-Keyed\200506\0606"Private strSourceDirPath As String = "D:\Data-Keyed\200506\0606" Private strDestiQmDirPath As String = "D:\Data-Qm\200506\0606" Private strDestiNonQmDirPath As String = "D:\Data-NonQm\200506\0606" Private Sub FileSystemWatcher1_Created(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles FileSystemWatcher1.Created 'e.FullPath是txt文件的包括绝对路径的全名 ScanTheCreatedTxtFile(e.FullPath) End Sub Private Sub ScanTheCreatedTxtFile(ByVal FullFileName As String)
Dim strFileName As String strFileName = FullFileName.Substring(FullFileName.LastIndexOf("\") + 1, FullFileName.Length - FullFileName.LastIndexOf("\") - 1) Dim sr As StreamReader = New StreamReader(FullFileName) Dim line As String ' Read and display the lines from the file until the end ' of the file is reached. Do line = sr.ReadLine() If line Is Nothing Then '没问号 sr.Close() File.Copy(FullFileName, strDestiNonQmDirPath & "\" & strFileName) Exit Do ElseIf line.IndexOfAny("?") <> -1 Then '有问号 sr.Close() File.Copy(FullFileName, strDestiQmDirPath & "\" & strFileName) Exit Do End If Loop Until line Is Nothing sr.Close() End Sub
Me.FileSystemWatcher1.Filter = "*.txt"
Me.FileSystemWatcher1.NotifyFilter = System.IO.NotifyFilters.LastWrite
Me.FileSystemWatcher1.Path = "D:\Data-Keyed\200506\0606"Private strSourceDirPath As String = "D:\Data-Keyed\200506\0606"
Private strDestiQmDirPath As String = "D:\Data-Qm\200506\0606"
Private strDestiNonQmDirPath As String = "D:\Data-NonQm\200506\0606"
Private Sub FileSystemWatcher1_Created(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles FileSystemWatcher1.Created
'e.FullPath是txt文件的包括绝对路径的全名
ScanTheCreatedTxtFile(e.FullPath) End Sub Private Sub ScanTheCreatedTxtFile(ByVal FullFileName As String)
Dim strFileName As String
strFileName = FullFileName.Substring(FullFileName.LastIndexOf("\") + 1, FullFileName.Length - FullFileName.LastIndexOf("\") - 1) Dim sr As StreamReader = New StreamReader(FullFileName)
Dim line As String
' Read and display the lines from the file until the end
' of the file is reached.
Do
line = sr.ReadLine()
If line Is Nothing Then
'没问号
sr.Close()
File.Copy(FullFileName, strDestiNonQmDirPath & "\" & strFileName)
Exit Do
ElseIf line.IndexOfAny("?") <> -1 Then
'有问号
sr.Close()
File.Copy(FullFileName, strDestiQmDirPath & "\" & strFileName)
Exit Do
End If Loop Until line Is Nothing sr.Close() End Sub