【问题标题】:Select a folder, lookup for a specific filetype, and if afirmative write in textbox选择一个文件夹,查找特定的文件类型,如果确定,则在文本框中写入
【发布时间】:2017-12-20 22:30:36
【问题描述】:

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

这是我目前得到的:

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

最好的问候 安德烈

【问题讨论】:

  • 我不太明白你的问题。但我可以看到您的流在While 循环中没有移动。您可能在此循环中忘记了 line = fich_time.ReadLine
  • OpenFile() n'existe pas comme methode pour un streamreader et encore moin pour un string。 Si je comprends ce que tu veux faire....Tu cherche pour un fichier en particulier et après tu recherche pour une ligne dans le fichier en mode texte qui contient des données dont tu as besoin et inscrit le tout dans un 文本框。最准确的?
  • 当您将文件作为参数发送到 StreamReader 构造函数时,它就可以读取了。您无需单独操作即可打开它。

标签: vb.net stream folderbrowserdialog


【解决方案1】:

试试这个,别忘了关闭你的文件

    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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-21
    • 2018-04-29
    • 1970-01-01
    • 1970-01-01
    • 2023-02-20
    • 1970-01-01
    • 2019-06-20
    相关资源
    最近更新 更多