File Access functions
11/10/2019
// LogToFile constants
const LOG_DATETIME := 1; // log Core-Style DateTimeStr in front of log entry
//BinaryFile constants
const OPENMODE_IN := 0x01; // (input) Allow input operations on the stream
const OPENMODE_OUT := 0x02; // (output) Allow output operations on the stream
const OPENMODE_ATE := 0x04; // (at end) Set the stream's position indicator to the end of the stream on opening
const OPENMODE_APP := 0x08; // (append) Set the stream's position indicator to the end of the stream before each output operation
const OPENMODE_TRUNC := 0x10; // (truncate) Any current content is discarded, assuming a length of zero on opening
const SEEKDIR_BEG := 0x00; // beginning of sequence
const SEEKDIR_CUR := 0x01; // current position within sequence
const SEEKDIR_END := 0x02; // end of sequence
const LITTLE_ENDIAN := 0x00;
const BIG_ENDIAN := 0x01;
// ListDirectory constants
const LISTDIR_LIST_DIRS := 0x1;
const LISTDIR_DONT_LIST_DIRS := 0x0;
const LISTDIR_NO_FILES := "";
const LISTDIR_ALL_FILES := "*";
FileExists( filename )
Checks for the existence of a file based on Filename parameter.
1 on success
"Invalid parameter type"
"Error in filename descriptor"
"No parent path traversal please."
fileaccess.cfg
ReadFile( filename )
Reads a text file, returning the contents as an array of strings, removing newlines.
By default, no package has any file access rights. To grant access, see config/fileaccess.cfg
returns array of strings
"Invalid parameter type"
"Error in filename descriptor"
"No parent path traversal please."
"Access denied"
"File not found: X"
fileaccess.cfg
WriteFile( filename, textcontents )
Writes a new file to disk, appends newlines, creates file if it does not exist, renames existing file to filename.bak
By default, no package has any file access rights. To grant access, see config/fileaccess.cfg
1 or error
"Invalid parameter type"
"Error in filename descriptor"
"No parent path traversal please."
"Access denied"
"File not found: X"
"Error during write."
"Unable to remove filenameX: reasonY
"Unable to rename filenameX: to filenameZ: reasonY
fileaccess.cfg
AppendToFile( filename, textlines )
Appends to a text file, adding newlines. Creates file if it does not exist.
By default, no package has any file access rights. To grant access, see config/fileaccess.cfg
1 or error
"Invalid parameter type"
"Error in filename descriptor"
"No parent path traversal please."
"Access denied"
"Unable to open file: X"
"Error during write."
fileaccess.cfg
LogToFile( filename, line, flags := 0 )
Appends a single line to a text file, adds newlines, creates file if it does not exist.
By default, no package has any file access rights. To grant access, see config/fileaccess.cfg
file.em constants for flags:
const LOG_DATETIME := 1; // log Core-Style DateTimeStr in front of log entry
1 or error
"Invalid parameter type"
"Error in filename descriptor"
"No parent path traversal please."
"Access denied"
"Unable to open file: X"
"Error during write."
fileaccess.cfg
OpenBinaryFile( filename, mode := OPENMODE_IN, endian := LITTLE_ENDIAN )
Opens BinaryFile stream
By default, no package has any file access rights. To grant access, see config/fileaccess.cfg
file.em constants for mode:
const OPENMODE_IN := 0x01; // (input) Allow input operations on the stream
const OPENMODE_OUT := 0x02; // (output) Allow output operations on the stream
const OPENMODE_ATE := 0x04; // (at end) Set the stream's position indicator to the end of the stream on opening
const OPENMODE_APP := 0x08; // (append) Set the stream's position indicator to the end of the stream before each output operation
const OPENMODE_TRUNC := 0x10; // (truncate) Any current content is discarded, assuming a length of zero on opening
file.em constants for endian:
const LITTLE_ENDIAN := 0x00;
const BIG_ENDIAN := 0x01;
BinaryFile or error
"Invalid parameter type"
"Error in filename descriptor"
"No parent path traversal please."
"Access denied"
BinaryFile
fileaccess.cfg
CreateDirectory( dirname )
Creates directory
1 or error
"Invalid parameter type"
"Error in dirname descriptor"
"No parent path traversal please."
"Directory already exists."
"Could not create directory."
ListDirectory( dirname, extension := LISTDIR_ALL_FILES, listdirs := LISTDIR_DONT_LIST_DIRS )
List directory content
extension param can be extension without "." or file.em constant:
const LISTDIR_NO_FILES := "";
const LISTDIR_ALL_FILES := "*";
file.em constants for listdirs:
const LISTDIR_LIST_DIRS := 0x1;
const LISTDIR_DONT_LIST_DIRS := 0x0;
array of strings or error
"Invalid parameter type"
"Error in dirname descriptor"
"No parent path traversal please."
"Directory not found."
CreateXMLFile()
creates an empty XMLFile object
XMLFile object or error
XMLFile
OpenXMLFile( filename )
opens given filename and returns XMLFile object, fileaccess.cfg is checked
XMLFile object or error
XMLFile
fileaccess.cfg