fs. dir

Represents a handle for interacting with a directory opened by opendir().

Example
const handle = opendir(…);

handle.read();

handle.tell();
handle.seek(…);

handle.close();

handle.error();

Methods

close() → {boolean}nullable

Closes the directory handle.

Closes the underlying file descriptor referring to the opened directory.

Returns true if the handle was properly closed.

Returns null if an error occurred.

Returns: boolean

error() → {string}nullable

Query error information.

Returns a string containing a description of the last occurred error or null if there is no error information.

Returns: string
Example
// Trigger file system error
unlink('/path/does/not/exist');

// Print error (should yield "No such file or directory")
print(error(), "\n");

read() → {string}nullable

Read the next entry from the open directory.

Returns a string containing the entry name.

Returns null if there are no more entries to read.

Returns null if an error occurred.

Returns: string

seek(offset) → {boolean}nullable

Set read position.

Sets the read position within the open directory handle to the given offset value. The offset value should be obtained by a previous call to tell() as the specific integer values are implementation defined.

Returns true if the read position was set.

Returns null if an error occurred.

Parameters:
NameTypeDescription
offsetnumber

Position value obtained by tell().

Returns: boolean
Example
const handle = opendir("/tmp");
const begin = handle.tell();

print(handle.read(), "\n");

handle.seek(begin);

print(handle.read(), "\n");  // prints the first entry again

tell() → {number}nullable

Obtain current read position.

Returns the current read position in the open directory handle which can be passed back to the seek() function to return to this position. This is mainly useful to read an open directory handle (or specific items) multiple times.

Returns an integer referring to the current position.

Returns null if an error occurred.

Returns: number