Files¶
KatieLib provides a few extra functions to make working with files easier.
It should be noted that there are two different kinds of paths used throughout the shim: physical file system paths and asset manager paths.
Physical paths refer to files on the actual filesystem of the device and should almost always be absolute; they cannot access the APK’s asset directory normally, since those files are actually kept in a stillZIP’d copy of the APK on the device. Generally speaking, most modules work with physical paths unless otherwise noted.
Asset manager paths refer to paths passed to the resource manager, where
they are typically relative to the APK’s asset directory (though can
also access internal data via user:// paths, or load resources over
HTTP using http:// paths).
-
knWriteFile(path:
string, content:string):true¶ Write a file with the given contents, which may contain embedded zeros.
Changed in version 18: Raises a lua error on any failure, and for legacy reasons returns
trueto indicate success.
-
knReadFile(path:
string):string|nil¶ Read the contents of the given file. Returns a string with the contents on success, even if the file is empty, or
nilon failure to open the file.Changed in version 18: Other kinds of failures (like memory allocation and I/O errors) raise Lua errors instead of returning
nil.
-
knRenameFile(oldPath:
string, newPath:string):boolean¶ Renames the file at
oldPathtonewPath, moving the file if needed. Returnstrueon success andfalseon failure.
-
knDeleteFile(path:
string):boolean¶ Deletes the file at the given path. Returns
trueon success andfalseon failure.
-
knIsFile(path:
string):boolean¶ Check if the file at the given path exists and can be read. Returns
trueif so, orfalseif not.
-
knMakeDir(path:
string):boolean¶ Creates the directory at
pathusingmkdir(path, 0777). Returnstrueon success,falseon failure. Note that if the directory already exists, this will returnfalse.
-
knListDir(path:
string):table¶ Return a list of file names in the directory as a table, not including the special entries
.and...
-
knIsDir(path:
string):boolean¶ Check if the file system node at
pathis a directory and is readable. Returntrueif it is andfalseif it is not.