Updating text files with new lines from another text file

yathinj@gmail.com

New member
Joined
Oct 27, 2008
Messages
4
Programming Experience
Beginner
Hi all ,
I am working on the VB.net project , which downloads text files to my local directory from a server.

Sample text file is provided below
! 07-08-30 05:12:12 00 0002.1159 Information: Component in tape
! 07-08-30 05:13:03 00 0002.1548 Information: RIT1
! 07-08-30 05:16:27 00 0002.1245 Information: End-of-reel
! 07-08-30 05:16:27 00 0002.0027 Question: End of reel?
! 07-08-30 05:16:29 00 0002.1217 Information: Read in lot

My problem is this log file on the server generates new entry every few minutes and when i run my VB program i want only the new line to be updated on the local file.

In other words I want the text file on my local directory to be updated with new lines from the text files located on the server.

Can some one please help me with the code to do the text file updating. Thanks
 
Your VS2008 solution:
VB.NET:
Private readlines As Integer

Private Function GetNewLines() As String()
    Dim alllines As New List(Of String)(IO.File.ReadAllLines("input.txt"))
    Dim newlines() As String = alllines.GetRange(readlines, alllines.Count - readlines).ToArray
    readlines = alllines.Count
    Return newlines
End Function
Each time you call the GetNewLines function it only returns the new lines.
 
I'm not sure that's the answer to the question being asked. Here is some example code to append:


VB.NET:
Dim serverLines() as String 'array
serverLines = GetLogFileLinesFromServer() 'i dont know how you do this method, it's up to you

Dim sw as New StreamWriter("c:\logfile.txt", True) 'true == append to file

For Each line As String in serverLines
  sw.AppendLine(line)
Next line

sw.Close()
sw.Dispose()

Note if youre not getting your logfile as an array of lines it doesnt matter:

VB.NET:
Dim serverEntireFile as String 'entire file in one string
serverEntireFile = GetLogFileFromServer() 'i dont know how you do this method, it's up to you

Dim sw as New StreamWriter("c:\logfile.txt", True) 'true == append to file

sw.AppendLine(serverEntireFile )

sw.Close()
sw.Dispose()
 
Back
Top