Ending Streamreader at end of file?

vb_noob

New member
Joined
Aug 28, 2002
Messages
2
There are empty lines in the file im reading from so using
.peek -1 wont work. Any ideas how to get this loop to stop at the end of the file? Thanks in advance.

Dim textLine As String, fileName As String, dirName As String
Dim outPath as String
Dim fileDate As Date
Dim delim As Integer
Dim fs As FileStream, sr As StreamReader
Dim sW As StreamWriter, outs As FileStream


fs = New FileStream(sName, FileMode.Open, FileAccess.Read)
outs = New FileStream(outputFile, FileMode.Append)
sW = New StreamWriter(outs)
sr = New StreamReader(fs)
textLine = sr.ReadLine

Do While ???????
textLine = sr.ReadLine
textLine = Trim$(textLine)
If Len(textLine) > 0 Then
If Left$(textLine, 13) = "Directory of " Then
dirName = Mid$(textLine, 14)
Else
If dirName <> "" Then
If IsDate(Left(textLine, 8)) Then
fileDate = CDate(Left(textLine, 8))
If fileDate < dateRequired Then
delim = InStr(38, textLine, " ", _ CompareMethod.Text)
If delim > 0 Then
fileName = Trim$(Mid$(textLine, delim))
dirName = Replace(dirName, ":", "$")
outPath = dirName & "\" & fileName
sW.WriteLine(outPath)
End If
End If
End If
End If
End If
End If

Loop
sr.Close()
sW.Close()
 
The FileStream class has a Position property, which returns the
current position being read from in the stream. Compare this to
the FileStreams length property to see if the position is at the
end of the file (if Length equals Position).

You want to loop while they are NOT equal, so this will work fine:

Code:
Do While Not fs.Position = fs.Length
 
Last edited by a moderator:
Back
Top