Skip to main content
A file on a [Machine]‘s filesystem. Obtain via [Machine.file]. The handle stays bound to the machine it came from: paths are meaningful only on that machine, and all operations run there. Content access is text-oriented ([File.read] trims, [File.write] takes strings).

Constructor

Returns

File

Methods

copyTo()

Copies the file to dest on the same machine, returning a handle to the copy. Fails when dest already exists. Local: an absolute dest is used as-is. A relative dest is joined to the SimularFiles root (.. is kept — this is a default base, not a sandbox). Android: dest must be absolute.

Parameters

string
required

Returns

File

delete()

Deletes the file, invalidating the handle.

extension()

The file extension, if any.

Returns

null | string

isReadonly()

Whether the file is read-only.

Returns

boolean

modified()

The last modification time as milliseconds since the Unix epoch.

Returns

number

moveTo()

Moves the file to dest on the same machine. Fails when dest already exists. Path resolution as in [File.copyTo].

Parameters

string
required

name()

The file name (last component of the path).

Returns

string

path()

The file’s path on its machine, as a string.

Returns

string

read()

Reads the file and returns its trimmed contents.

Returns

string

rename()

Renames the file in place (same parent directory). newName must be a single filename component.

Parameters

string
required

size()

The file size in bytes.

Returns

number

write()

Writes content to the file, overwriting it — or appending, with a newline inserted first when the file already has content. Parent directories are created if needed.

Parameters

string
required
boolean
required