选择一个文件夹,查找特定的文件类型,以及是否在文本框中写入

问题描述 投票:0回答:1

我正在开发一个程序来寻找特定的文件类型(一个文件夹中只存在一种)。我选择文件夹,扫描它以查找文件类型,以防他找到文件流并将查询结果写入文本框。

这是我到目前为止所得到的:

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方法是字符串的成员,到目前为止我知道但是我应该使用什么函数来使这个工作?

最好的问候其他人

vb.net stream folderbrowserdialog
1个回答
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
© www.soinside.com 2019 - 2024. All rights reserved.