I have a logging sub routine, that writes log records to a text file. The
sub routine is copied below... The issue I have, is that this file can get
very large and as the process runs, it gets slower and slower, with the size
of the file getting very big.
Is there any way, with the scripting object, to only append to the text
file, without having to read the entire file into a variable and then append
to the variable, then write the variable back to the file.... Something like
the normal VB command of 'open for append as #1', which allows the text
record to write to the end of the file, without having to read the entire
file into memory. Is the scripting.filesystemobject, the correct object to
use, or is there another object that should be used?
This is a vbs script, but I have tried using the object browser (with the
Microsoft Scripting Runtime reference loaded) and it does not show any
'append' type method...
sub doLogging(inRecord)
dim fsoObject 'As script object
dim strText 'As string
set fsoObject = CreateObject("Scripting.FileSystemObject)
with fsoObject.OpenTextFile("c:\log.txt")
strText = .ReadAll
.Close
end with
fsoObject.DeleteFile "c:\log.txt", True
strText = strText & vbCrLf
if trim(inRecord) <> "" then strText = strText & inRecord
with fsoObject.CreateTextFile("c:\log.txt")
.Write strText
.Close
end with
set fsoObject = nothing
end sub