docs
Built In
File Handling

Intro

File Handling is a seamless way to deal and do operations on files, and it is a very important part of any programming language.

Kin provides KIN_INYANDIKO in-built utility to handle file operations.

With Kin you can easity read, write, append, and delete files.

Paths are resolved relative to the directory of the global filename (the .kin file you ran), not only the process working directory.

Reading Files

By using KIN_INYANDIKO.soma(path-to-file) method, you can read the content of a file located in path-to-file.

Ex

reka file_content = KIN_INYANDIKO.soma("path-to-file")
tangaza_amakuru(file_content)

File Content of the provided file will be printed.

Writing Files

By using KIN_INYANDIKO.andika(path-to-file, content) method, you can write content to a file located in path-to-file.

Ex

reka file_content = injiza_amakuru("Enter the content to write to the file: ")
reka written =  KIN_INYANDIKO.andika("path-to-file", file_content)
niba (written) {
  tangaza_amakuru("Content was written to the file")
} niba_byanze {
  tangaza_amakuru("Failed to write content to a file at ", path-to-file)
}

Content will be written to the provided file. KIN_INYANDIKO.andika() returns nibyo on success, or an error message string on failure — never sibyo. Check ubwoko(result) or compare to nibyo.

Appending to a File

By using KIN_INYANDIKO.vugurura(path-to-file, content) method, you can apeend content to a file located in path-to-file.

Ex

reka new_file_content = injiza_amakuru("Enter the content to append to the file: ")
reka appended =  KIN_INYANDIKO.vugurura("path-to-file", new_file_content)
niba (appended) {
  tangaza_amakuru("Content was appended to the file")
} niba_byanze {
  tangaza_amakuru("Failed to appended content to a file at ", path-to-file)
}

Content will be appended to the provided file. KIN_INYANDIKO.vugurura() returns nibyo on success, or an error message string on failure — never sibyo.

Deleting Files

By using KIN_INYANDIKO.siba(path-to-file) method, you can delete a file located at path-to-file.

reka removed = KIN_INYANDIKO.siba("path-to-file")
niba (removed == nibyo) {
  tangaza_amakuru("dosiye yasibwe")
} niba_byanze {
  tangaza_amakuru(removed)
}

Returns nibyo on success, or an error message string on failure — never sibyo.