open file | ||||||||||
Type | command | |||||||||
Dictionary | LCS | |||||||||
Library | LiveCode Script | |||||||||
Syntax |
| |||||||||
Summary | Opens a file so its contents can be accessed or modified. | |||||||||
Introduced | 1.0 | |||||||||
Changes | From 7.0, it's possible to specify an encoding for the file being opened. By doing so, you can straight read or write to a file without having to call textEncode or textDecode; the encoding supported by open file are the same as these text encoding functions. If no encoding is provided, then open file tries to read a Byte Order Mark (BOM) exists at the beginning of the file. In success, the encoding is adapted and the BOM is ignored. | |||||||||
OS | mac, windows, linux, ios, android | |||||||||
Platforms | desktop, server, mobile | |||||||||
Parameters |
| |||||||||
Example |
| |||||||||
Values |
| |||||||||
Related | Property: fileType, umask Control Structure: function Keyword: characters, file, URL Constant: return Function: result, tempName, textDecode, textEncode Command: write to file, open file, put, constant, read from file, get, close file, answer file Glossary: return, null, property, file, port, command, Windows, OS X, type signature, creator signature, Mac OS, Unix, ASCII | |||||||||
Security | disk | |||||||||
Description | Use the open file command to create a file or prepare an existing file for use by the read from file or write to file commands. You can optionally specify either text or binary mode. If you specify text mode, when you use the write to file command to put data in the file, any line feed and return characters are translated to the appropriate end-of-line marker for the current operating system before being written to the file. The end-of-line marker on Mac OS and OS X systems is a return character; on Unix, a line feed; on Windows, a CRLF. When you use the read from file command to get data from the file, end-of-line markers are translated to the return constant, and any null characters are translated to spaces (ASCII 32). If you specify binary mode, null characters and end-of-line markers are not translated. If you do not specify a mode, the file is opened in text mode. Use the for read form to open the file for reading. If the file is opened for reading, you can use the read from file command to examine its contents, but you cannot modify it. If you use the for read form and the file does not exist, LiveCode does not create it, and the result function returns "Can't open that file.". Use this form for files on CD-ROM and other read-only media. Use the for write form to open the file for writing. If the file is opened for writing, the write to file command replaces the file's contents from the starting point to the end of the file.
Use the for update form to open the file for both reading and writing. If the file is opened for update, you can use both the read from file and write to file commands to examine or change it, and writing to the file places the data at the specified position without replacing other characters beyond the written data. Use the for append form to open the file for writing. If the file is opened for append, the write to file command adds its data to the end of the file without replacing its current contents. If you do not specify a form, the file is opened for update. On Mac OS and OS X systems, if the file does not already exist (so that the open file command creates it), the new file's creator signature and file type are set to the values in the fileType property. Any files you have opened are closed automatically when you quit the application. You can use the open file command to open a serial port on Mac OS or Windows systems. On Mac OS systems, specify either "printer:" or "modem:". On Windows systems, specify either "COM1:", "COM2:", or up to "COM9:". Set the serialControlString property before opening the port to specify the baud rate and other settings.
| |||||||||
Tags | file system |