From MiniScript Wiki
Jump to navigation Jump to search

In Mini Micro and command-line MiniScript, the function returns a FileHandle object that enables further reads, writes, or updates of the file.


Parameter Name Default Value Meaning
path "" full or partial path to the file of interest
mode "rw+" file mode (see below)

File Modes

The second parameter to specifies whether the file is opened for reading, writing, or both.

Mode Description Starting Position
r open for reading (The file must exist) beginning
w open for writing (creates file if it doesn't exist). Deletes content and overwrites the file. beginning
a open for appending (creates file if it doesn't exist) end
r+ open for reading and writing (The file must exist) beginning
w+ open for reading and writing. If file exists deletes content and overwrites the file, otherwise creates an empty new file beginning
a+ open for reading and writing (append if file exists) end

When a file is opened with update mode ( '+' as the second or third character in the mode argument), both input and output may be performed on the associated stream.

Writing and appending modes will attempt to create a file of the given name, if no such file already exists. If this operation fails, will return null.


This appends a new line to an existing text file (creating it if it does not already exist).

f ="test.txt", "a")
f.write char(13) + "Hello world!"