2017-12-20 16 views
0

特定のファイルタイプを探すプログラムを開発しています。 フォルダを選択し、ファイルのストリームを見つけた場合にファイルタイプをスキャンし、テキストボックスにクエリ結果を書き込みます。これまでのところ、私はそれを知っているが、どのような機能は、私はこの仕事をするために使用する必要があり、フォルダを選択し、特定のファイルタイプを検索し、テキストボックスに肯定的な書き込みを行う場合

For Each file1 In IO.Directory.GetFiles(folderA, file_A) 
      Using fich_time As New StreamReader(file1) 
       line = fich_time.ReadLine 


       Try 
        myStream_time = file1.OpenFile() 
        If (myStream_time IsNot Nothing) Then 

         line = fich_time.ReadLine 

         While Not fich_time.EndOfStream 

          If line.Contains(" CPU Time for A Analysis") Then 

           If line.Contains("sec") = True Then 
            txt_A.Text = line 
            txt_A.Text = Replace$(txt_A.Text, Space(1), Space(0)) 
            txt_A.Text = Regex.Replace(txt_A.Text, "[^0-9.]", "") 

           Else 
            txt_A.Text = line 
            txt_A.Text = Replace$(txt_A.Text, Space(1), Space(0)) 
            txt_A.Text = Regex.Replace(txt_A.Text, "[^0-9.]", "") 
            txt_A.Text = txt_A.Text * 3600 

           End If 
          End If 
         End While 
        End If 
       Finally 

       End Try 

      End Using 
     Next 

主なエラーはのOpenFileメソッドは文字列のメンバーである??:

これは私がこれまでに得たものです

よろしく アンドレ

+0

を閉じることを忘れないでください。しかし、あなたのストリームは 'While'ループで動いていないことがわかります。おそらく、このループの中で 'line = fich_time.ReadLine'を忘れたでしょう。 – Bob

+0

OpenFile()は、ストリームリーダとアンコールストリームをアンストールします。あなたの声を聞いてください。あなたの声を聞かせてください。あなたの声を聞かせてください。あなたの声を聞かせてください。正確なの? – Chillzy

+0

StreamReaderコンストラクターに引数としてファイルを送信すると、読み取り準備が整います。それを開くには別の操作は必要ありません。 – Mary

答えて

0

これを試してみて、私は本当にあなたの質問を理解していないファイル

For Each file1 In IO.Directory.GetFiles(folderA, file_A) 
     Using fich_time As New StreamReader(file1) 
      Try 
       While Not fich_time.EndOfStream 
        line = fich_time.ReadLine 
        If line.Contains(" CPU Time for A Analysis") Then 
         If line.Contains("sec") = True Then 
          txt_A.Text = line 
          txt_A.Text = Replace$(txt_A.Text, Space(1), Space(0)) 
          txt_A.Text = Regex.Replace(txt_A.Text, "[^0-9.]", "") 
         Else 
          txt_A.Text = line 
          txt_A.Text = Replace$(txt_A.Text, Space(1), Space(0)) 
          txt_A.Text = Regex.Replace(txt_A.Text, "[^0-9.]", "") 
          txt_A.Text = txt_A.Text * 3600 
         End If 
        End If 
       End While 
      Catch ex As Exception 
       MsgBox(ex.Message) 
      Finally 
       fich_time.Close() 
      End Try 
     End Using 
    Next 
関連する問題