WriteAllText

Writes text to a file.


Syntax

FileSystem.WriteAllText(File, Text, Append)

FileSystem.WriteAllText(File, Text, Append, Encoding)


Parameters


File

String, input



Name and path of the file to read.


Text

String, input



Text to be written to the file.


Append

Boolean, input



True to append to the contents of the file; False to overwrite the contents of the file.


Encoding

Character encoding to use when writing to the file. Default is ASCII.


Remarks


Encoding



ASCII

Gets an encoding for the ASCII (7-bit) character set.


Unicode

Gets an encoding for the UTF-16 format using the little endian byte order.


UTF32

Gets an encoding for the UTF-32 format using the little endian byte order.


UTF7

Gets an encoding for the UTF-7 format.


UTF8

Gets an encoding for the UTF-8 format.



Examples

This example writes a text string to the specified file, overwriting any existing text in the file::


Sub Main()

FileSystem.WriteAllText "C:\Users\Public\My Directory\Test.txt", "This is new text to be added.", False

End Sub


This example writes the names of the files in the Flex Terminal Emulator install folder to FileList.txt, inserting a carriage return between each for better readability:


Sub Main()

For Each foundFile In GetFiles("C:\Program Files\FlexSoftware\FlexTerm")

foundFile = foundFile & vbCrLf

WriteAllText "C:\Users\Public\FileList.txt", foundFile, True

Next

End Sub