Skip to main content

Constructor

Creates a handle to a file at the given path. If create_missing is true, the file (and all missing parent directories) is created when it does not already exist. If false, the call fails when the file does not exist.

Parameters

string
required
boolean
required

Returns

File

Methods

copyTo()

Copies the file to a new location, returning a handle to the copy.

Parameters

string
required

Returns

File

delete()

Deletes the file, invalidating the handle.

extension()

Returns the file extension, if any.

Returns

null | string

isReadonly()

Returns whether the file is read-only.

Returns

boolean

modified()

Returns the last modification time as milliseconds since the Unix epoch.

Returns

number

moveTo()

Moves the file to a new location. Falls back to copy + delete for cross-device moves.

Parameters

string
required

name()

Returns the file name (last component of the path).

Returns

string

path()

Returns the resolved absolute path.

Returns

string

read()

Reads the file and returns its trimmed contents.

Returns

string

rename()

Renames the file in place (same parent directory).

Parameters

string
required

size()

Returns the file size in bytes.

Returns

number

write()

Writes content to the file. When append is true and the file already has content, a newline is inserted before appending. When append is false, the file is overwritten. Parent directories are created if needed.

Parameters

string
required
boolean
required