PowerBasic Museum 2020-A

Legacy Software (PBWIN 9.0+/PBCC 5.0+) => Windows Script Runtime => Source Code => Scripting => FileSystemObject => Topic started by: José Roca on July 14, 2008, 02:04:00 AM

Title: IFolder.CreateTextFile
Post by: José Roca on July 14, 2008, 02:04:00 AM


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