什么是语法用于读取直到文件中的VBScript SSIS结束?

Dim readFile As FileInfo = New FileInfo(logHourlyName)
If readFile.Exists() Then
   Dim textStream As StreamReader = readFile.OpenText()
   Dim strLine As String
   Do While Not EOF    <--- what goes here?
       curLine = textStream.ReadLine()
   Loop
   textStream.Close()
End If

编辑:实际上,我试图让该文件的最后一行的值。所以,阅读,直到没有EOF是不太一样的阅读文件的末尾。但是我砍了这么多,我不得不示例代码差。

有帮助吗?

解决方案

http://msdn.microsoft.com/ EN-US /库/ system.io.streamreader.aspx

Dim readFile As FileInfo = New FileInfo(logHourlyName)
If readFile.Exists() Then
   Dim textStream As StreamReader = readFile.OpenText()
   Dim strLine As String
   Do
       curLine = textStream.ReadLine()
   Loop Until curLine Is Nothing
   textStream.Close()
End If

如果你只是想最后一行:

Dim readFile As FileInfo = New FileInfo(logHourlyName)
Dim lastLine As String
If readFile.Exists() Then
   Dim textStream As StreamReader = readFile.OpenText()
   Dim strLine As String
   Do
       curLine = textStream.ReadLine()
       If Not curLine Is Nothing Then lastLine = curLine
   Loop Until curLine Is Nothing
   textStream.Close()
End If

其他提示

下面是一种方法,读出刚才的最后一行没有通过整个文件循环。 它转到文件的末尾并开始阅读向后直到碰到另一个LF字符,它表示第二到最后一行的末尾,然后它只是读取该行。

在拥有数百万行的大文件,这降低成本,以阅读几个字节。

您可以取消Dts.Events.FireInformation码什么是你的输出窗口中发生的事情。

    Dim i As Integer
    Dim CurrentByte As Integer
    Dim Trailer As String

    i = 1

    Using reader As StreamReader = New StreamReader("c:\temp\SourceFile.txt")
        Do While CurrentByte <> 10 'while we are not finding the next LF character
           reader.BaseStream.Seek((-1 * i) - 2, SeekOrigin.End) 'seeking backwards from the last position in the file minus the last CRLF
            'Dts.Events.FireInformation(0, "Now at position", reader.BaseStream.Position().ToString, "", 0, False)
            CurrentByte = reader.BaseStream.ReadByte 'read the next byte, this will advance pointer position
            'Dts.Events.FireInformation(0, "Current ASCII Code", CurrentByte & " Character:" & Chr(CurrentByte), "", 0, False)
            i = i + 1 'go to the next character                 
        Loop
        Trailer = reader.ReadLine 'we exited on the LF character, so we are at the beginning of trailer line
        Dts.Events.FireInformation(0, "   Trailer:", Trailer, "", 0, False)
    End Using
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top