That did the trick. Thank you.
Dim textFilesLocation As String
Dim fileToImport As String
Dim fileText()
Dim i As Int32
textFilesLocation = "D:\Data\"
fileToImport = textFilesLocation & Dir(textFilesLocation)
While fileToImport <"D:\Data\"
fileText = File.ReadAllLines(fileToImport)
For i = 0 To fileText.Length - 1
If InStr(fileText(i).ToString, "First Pub Date:",
CompareMethod.Text) 0 Then
fileText(i) = "First Pub Date: " &
Format(DateAdd(DateInterval.Day, 84, CDate(Mid(fileText(i).ToString, 24))),
"Short Date")
End If
If InStr(fileText(i).ToString, "Last Pub Date:", CompareMethod.Text)
0 Then
fileText(i) = "Last Pub Date: " &
Format(DateAdd(DateInterval.Day, 84, CDate(Mid(fileText(i).ToString, 15))),
"Short Date")
End If
If InStr(fileText(i).ToString, "Sale Date:", CompareMethod.Text) 0
Then
fileText(i) = "Sale Date: " & Format(DateAdd(DateInterval.Day,
84, CDate(Mid(fileText(i).ToString, 11))), "Short Date")
End If
Next
File.WriteAllLines(fileToImport, fileText)
fileToImport = textFilesLocation & Dir()
End While
MsgBox("done")
"Göran Andersson" <gu***@guffa.comwrote in message
news:uw**************@TK2MSFTNGP03.phx.gbl...
Keith G Hicks wrote:
>I'm trying to read a text file and alter the contents of specific lines
in
the file. I know how to use streamreader to read each line of a file. I'm
doing that already to get the data into a database. What I need help with
is
on how to locate a specific line in the file, change it and then save the
updated text file. Can anyone help me out or point me to a site that
explains this clearly?
Files are not line based, so you can't change a line directly in the file.
Read the file into a string array using the File.ReadAllLines method,
change the line(s) you want, then save the lines to the file using the
File.WriteAllLines method.
If the file is too large to read into memory, read the lines using a
StreamReader, and write the changed lines to a temporary file using a
StreamWriter. Then delete the original file and rename the temporary file
to replace it.
--
Göran Andersson
_____
http://www.guffa.com