The following code illustrates the use of the
CreateTextFile method with an
IFolder object:
DIM fso AS IFileSystem
DIM pFolder AS IFolder
DIM pStm AS ITextStream
' Create an instance of the FileSystemObject
fso = NEWCOM "Scripting.FileSystemObject"
' Get a reference to the IFolder interface
pFolder = fso.GetFolder(UCODE$("C:\MyFolder"))
' Create a text stream
pStm = pFolder.CreateTextFile(UCODE$("Test.txt"), %VARIANT_TRUE, %VARIANT_FALSE)
' Write a string and an end of line to the stream
pStm.WriteLine UCODE$("This is a test.")
' Write more strings
pStm.Write UCODE$("This is a string.")
pStm.Write UCODE$("This is a second string.")
' Write two blank lines (the first will serve as an end
' of line for the previous write instructions) and another
' string and end of line to the stream
pStm.WriteBlankLines 2
pStm.WriteLine UCODE$("This is the end line.")
' Close the file
pStm.Close