Filesystem interface library of the Chaos language. You can install this spell with:
occultist install fs
and import it with:
import fs
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)
Close a file given by the file_descriptor
.
kaos> fs.close(fp)
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!
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)
Move a file from old_path
to new_path
.
kaos> fs.move("files/moveme.txt", "ignored/moveme.txt")
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")
Check if path
is a directory.
kaos> fs.is_dir("files/")
Check if path
is a file.
kaos> fs.is_file("files/readme.txt")