Skip to content

chaos-lang/fs

Repository files navigation

Filesystem interface library of the Chaos language. You can install this spell with:

occultist install fs

and import it with:

import fs

I/O

num fs.open(str filepath, str mode)

Open a file on path filepath with the file access mode mode and return the file descriptor.

kaos> num fp = fs.open("files/readme.txt", "r")

The list of file access modes are same as the fopen in C. (see reference)

void fs.close(num file_descriptor)

Close a file given by the file_descriptor.

kaos> fs.close(fp)

str fs.read(num file_descriptor)

Read the contents of a file given by the file_descriptor into a string.

kaos> num fp = fs.open("files/readme.txt", "r")
kaos> str text = fs.read(fp)
kaos> fs.close(fp)
kaos> print text
You read me!

void fs.write(num file_descriptor, str text)

Write the contents to a file given by the file_descriptor.

kaos> num fp = fs.open("files/writeme.txt", "w")
kaos> fs.write(fp, "You wrote me!\n")
kaos> fs.close(fp)

Filesystem Operations

void fs.move(str old_path, str new_path)

Move a file from old_path to new_path.

kaos> fs.move("files/moveme.txt", "ignored/moveme.txt")

void fs.copy(str src_filepath, str dst_filepath)

Copy the contents of a file on path src_filepath to a new file on dst_filepath.

kaos> fs.copy("files/copyme.txt", "ignored/copyme.txt")

bool fs.is_dir(str path)

Check if path is a directory.

kaos> fs.is_dir("files/")

bool fs.is_file(str path)

Check if path is a file.

kaos> fs.is_file("files/readme.txt")

About

Filesystem library of the Chaos language

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published