Gordy said:
Is it possible to write a script that searches an ASCII
file for a unique string and then places an EOF character
immediately after this string or deletes all text that
follows it?
Hi
If the text file is large, the following vbscript will take a while:
Const OpenAsASCII = 0 ' Opens the file as ASCII (TristateFalse)
Const OpenAsUnicode = -1 ' Opens the file as Unicode (TristateTrue)
Const OpenAsDefault = -2 ' Opens the file using the system default
Const OverwriteIfExist = -1
Const FailIfNotExist = 0
Const ForReading = 1
' path to original log file
sOrgFile = "C:\logs\test_org.txt"
' path to new log file
sNewFile = "C:\logs\test_new.txt"
' if you want to overwrite the original file, use the line below instead
'sNewFile = sOrgFile
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set fOrgFile = oFSO.OpenTextFile(sOrgFile, ForReading, _
FailIfNotExist, OpenAsASCII)
sText = fOrgFile.ReadAll
fOrgFile.Close
iPos = InStr(1, sText, "<end>", vbTextCompare)
If iPos > 0 Then
' <end> is found at position iPos
' get all text before (a.k.a. over) <end>, including <end>
sText = Left(sText, iPos + 4)
Set fNewFile = oFSO.CreateTextFile(sNewFile, _
OverwriteIfExist, OpenAsASCII)
fNewFile.WriteLine sText
fNewFile.Close
End If