I/O Expressions
A set of expressions related to input/output using files, streams, readers and sockets.
Some of these expressions are quite advanced and may be dangerous for beginners.
Accessing files can be quite slow as it relies on the machine's file system.
To avoid the program slowing down it may be preferable to access files on a background process.

File Expressions

[a] new file at %String%
Creates a new file at the given path. Returns that file object.
[the] file at %String%
Retrieves the existing file at the given path. Returns that file object. This may be null if the file does not exist.
%File% is [a] file
Whether the file is a file (not a folder.)
%File% is [a] folder
Whether the file is a folder (not a file.)
1
set {file} to a new file at "test.txt"
2
set {file} to the file at "test.txt"
3
assert {file} is a file
Copied!

File Properties

Property
Description
reader
The file's input stream.
writer
The file's output stream.
contents
The file's string contents.
name
The file name.
path
The file path.
1
set {file} to a new file at "test.txt"
2
assert name of {file} is "test.txt"
3
set the contents of {file} to "hello there"
4
assert the contents of {file} is "hello there"
Copied!

Stream Properties

Property
Description
all
The input stream's entire contents.
line
The input stream's next line.
1
set {file} to a new file at "test.txt"
2
set {writer} to writer of {file}
3
write "general kenobi" to {writer}
4
close {writer} // make sure to close streams when finished
5
set {reader} to reader of {file}
6
set {line} to line of {reader}
7
assert {line} is "general kenobi"
8
close {reader} // make sure to close streams when finished
Copied!