# Metadata
Platforms: desktop, server, mobile OS: mac, windows, linux, ios, android Introduced: 1.0 Security: disk
# Syntax
write value to {file pathName | stdout} [at {start | EOF | end}]
# Params
- value : The data to be written to the file. - pathName : The pathName specifies the name and location of the file you want to write to. It must be the same as the path you used with the open file command. The pathName is case-sensitive, even on platforms where file names are not case-sensitive. If you specify the name of a serial port on Mac OS or Windows systems, LiveCode writes to the specified port. The names of serial ports end in a colon (:). - start : The start specifies the character or byte position in the file where you want to begin writing. A positive number begins start characters after the beginning of the file; a negative number begins start characters before the end of the file. If you specify either of the synonyms EOF or end, the write begins after the last character in the file. If you don't specify a start, the write begins: - at the position determined by the seek command, or - if you haven't used the seek command, wherever the last read from file or write to file command to the file left off, or - if you haven't accessed the file with read from file or write to file since it was opened, after the last character (if the file was opened in append mode) or at the first character (if the file was opened in any other mode).
# Examples
write "test" to file "test.txt"
write linefeed to stdout
write "Hello" & return to stdout
write "ATZ" to file "modem:"
mouseUp local tFile put specialFolderPath("desktop") & "/test.txt" into tFile open file tFile for text write write "one 222" to file tFile -- Writes to the start of the file write "two" to file tFile at 4 -- Writes to the file from character 4 write " three" to file tFile at EOF -- Writes to the end of the file write " four" to file tFile at end -- Writes to the end of the file close file tFile mouseUp
# Description
Use the write to file command to change the contents of a file.
If the file was opened in write mode, the write to file command completely replaces the file contents from the start. For example, if the file originally contains "ABC", and you write "1" to it, after the write to file command is execute the file contains "1".
If the file was opened in update mode, if you write less data to the file than it already contains, the write to file command does not remove characters from it. For example, if the file originally contains "ABC", and you write "1" to it, after the write to file command is execute the file contains "1BC".
If the file was opened in append mode, the write begins at the end of the file.
>*Important:* After writing, you must close the file with the > close file command.
The write to stdout form writes to the standard output (on Unix systems). The standard output is always open, so you can write to it without first opening it.
>*Tip:* As an alternative to the open file and write to file > commands, you can also use the URL keyword with the > put command to change the contents of a file.
# Tags
# See
- **keyword:** file, characters, stdout, URL - **command:** open file, close file, write to driver, put - **function:** result - **glossary:** command, execute