Skip to content

WriteFileAsText()

ts
WriteFileAsText(filePath: string, data: string, offset: number, whence: number): respBase;

Writes the provided plain-text data to the filePath file in the VFS, starting at the specified offset computed from whence. The file is written as plain text.

Parameters

ParameterTypeExplanation
filePathstringThe fully qualified, root-based, POSIX path to the file in the VFS
datastringThe string of plain-text to write to the file
offsetnumberThe positional offset, computed from whence, where the write operation will begin
whencenumberOne of: FromStart, FromEnd

NOTE

offset and whence together determine where writing begins. 0,FromStart overwrites the file from the beginning; 0,FromEnd appends new data to the file.

Example

ts
var vfs = GetCurrentVFS();
if (vfs != null) {
    var resp = vfs.WriteFileAsText("/data/hello.txt", " World!", 0, FromEnd); 
    if (resp.Ok()) {
        Log("Data written to file"); // File now contains: Hello World!
    } else {
        Log("Error: " + resp.ErrorMsg());
    }
} else {
    Log("VFS was null");
}