write to file |
Type | command |
Dictionary | LCS |
Library | LiveCode Script |
Syntax | write <value> to {file <pathName> | stdout} [at {<start> | EOF | end}]
|
Summary | Places data in a file that has been opened with the open file
command.
|
Introduced | 1.0 |
OS | mac, windows, linux, ios, android |
Platforms | desktop, server, mobile |
Parameters | Name | Type | Description |
---|
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).
|
|
Example | 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
write "two" to file tFile at 4
write " three" to file tFile at EOF
write " four" to file tFile at end
close file tFile
mouseUp
|
Values | Name | Type | Description |
---|
The result | | The file to write to must be opened first with the open file command,
and the mode the file was opened in must be write, append, or update.
If the file is not open or is open read-only, the result function is
set to "File is not open for write.".
|
|
Related | Keyword: file, characters, stdout, URL
Command: open file, close file, write to driver, put
Function: result
Glossary: command, execute
|
Security | disk |
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 executed 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 executed 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 | file system |