Error getting tags :
error 404Error getting tags :
error 404 open file | revDocs | RunRev
Welcome Guest (Log in)
Product Edition
open file
Expander triangle

open file filePath [for [text | binary] {update | read | write | append}]

Desktop, Web and Server
Platform Support
MacOS,Mac OS X,Windows,Linux
Opens a file so its contents can be accessed or modified.

open file "temp.txt"
open file "/etc/Glossary" for write
open file (myFilePath "/" myFileName) for binary read

Additional Comments
Expander triangle

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.


The filePath specifies the name and location of the file you want to open or create. If you specify a name but not a location, Revolution assumes the file is in the defaultFolder. If the file you specify doesn't exist, Revolution creates it.

If you specify the name of a serial port on Mac OS or Windows systems, Revolution opens the specified port. The names of serial ports end in a colon (:).


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 don't 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 can't modify it. (If you use the for read form and the file does not exist, Revolution 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.

Important: before opening any file for writing to, remember to back up the file contents as Revolution will erase them even if you don't write to the file after opening it.

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 don't specify a form, the file is opened for update.

On Mac OS and OS X systems, if the file doesn't 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.

Note: On windows, it is imperative not to name a file with one of the reserved device names: CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8 and LPT9. Also do not use these names followed by an extension, for example, NUL.tx7.

Tip: As an alternative to the open file, read from file, and write to filecommands, you can also use the URLkeyword with get, put, and other commands to access the contents of a file.

User Comments
Expander triangle
User thumbnail
Gerard McCarthy
Apr 12, 2009
Open file can create a new file if it doesn't exist in a already existing folder. It doesn't create a new file if the subfolder doesn't exist.
User thumbnail
Apr 23, 2009
Be aware that it is NOT sufficient simply to specify the correct file extension under OSX to ensure the file will open with the correct application. For example if you used open file to write to a file "test.html" then used launch file "test.html", it would open in Text Edit. You would first need to set the creator type to Safari or Firefox to ensure it is recognized as belonging to a web browser. E.g. set fileType to "TEXTsfri" Now if launch the file it would open in Safari (or your preferred browser)
User thumbnail
Jun 4, 2010
If you are reading in a text file (for example) which contains high ascii values (such as curly quotes - numToChar(210) ) you will find that these are displayed as garbage in the variable watcher, or if you set directly to the field contents.
The solution is to encode and decode the content:
#tData contains your data read in from file put uniDecode(uniEncode(tData, "UTF8")) into tData
(All credit to Dave Cragg and Devin Assay for this tip)