Files in Simba are all integers, internal handles for Simba which on their turn point to operating system files. Functions like CreateFile and OpenFile return a file handle. You should not forget to close these when you no longer need them.
function CreateFile(const Path: string): Integer;
Create a file with Path. Raturns -1 on failure, otherwise returns the handle to the file.
function OpenFile(const Path: string; Shared: Boolean): Integer;
Opens file for reading. Opens shared if Shared is true. Returns -1 on failure, otherwise returns the handle to the file.
function RewriteFile(const Path: string; Shared: Boolean): Integer;
Opens file for rewriting. (File is cleared on open) Opens shared if Shared is true. Returns -1 on failure, otherwise returns the handle to the file.
function AppendFile(const Path: string): Integer;
Opens file for writing (appending). Returns -1 on failure, otherwise returns the handle to the file.
procedure CloseFile(FileNum: Integer);
Close the file defined by FileNum. Never forget to close your files!
function EndOfFile(FileNum: Integer): Boolean;
Returns true if the end of the file has been reached.
function ReadFileString(FileNum: Integer; var s: string; x: Integer):
Boolean;
Read x characters into string s from file FileNum. Returns true if the number of characters read equals x.
function WriteFileString(FileNum: Integer; s: string): Boolean;
Writes s to file FileNum. Returns false on failure.
function SetFileCharPointer(FileNum, cChars, Origin: Integer): Integer;
Seek through the file. Set the cursor to cChars from Origin.
Origin can be any of these:
{ File seek origins }
FsFromBeginning = 0;
FsFromCurrent = 1;
FsFromEnd = 2;
function FilePointerPos(FileNum: Integer): Integer;
Returns the position of the cursur in the file. (What character # you are at)
function DirectoryExists(const DirectoryName : string ) : Boolean;
Returns true if the directory exists.
function CreateDirectory(const DirectoryName : string) : boolean;
Creates a directory. Returns true on success.
function FileExists (const FileName : string ) : Boolean;
Returns true if the file exists.
function ForceDirectories(const dir : string) : boolean;
Creates multiple nested directories. Returns true on success.
function GetFiles(const Path, Ext : string) : TStringArray;
Returns the files in the directory defined by Path with extension Ext.
function GetDirectories(const path : string) : TStringArray;
Returns the directories in path.
procedure WriteINI(const Section, KeyName, NewString, FileName: string);
The following example writes to a specific Line in a Specified INI File.
program WriteINIExample;
Var Section, Keyname, NewString, FileName: String;
begin
Section := 'What subsection in the INI it is being Writen.';
KeyName := 'Space in the specified Subsection in which you string is writen.';
NewString := 'What your Writing into the INI file.';
FileName := 'The Name of the INI File you are writing too.';
WriteINI(Section, KeyName, NewString, ScriptPath + FileName);
end.
Note
ScriptPath will Automatically point the file finding to the same folder the script is saved in.
Note
This procedure can be used in conjunction with ReadINI to saved Player Data for the next time a script is run.
function ReadINI(const Section, KeyName, FileName: string): string;
The following example writes to a specific Line in a Specified INI File then Reads that line and prints it’s findings.
program WriteINIReference;
Var Section, Keyname, NewString, FileName: String;
begin
Section := 'What subsection in the INI it is being Writen.';
KeyName := 'Space in the specified Subsection in which you string is writen.';
NewString := 'What your Writing into the INI file.';
FileName := 'The Name of the INI File you are writing too.';
WriteINI(Section, KeyName, NewString, ScriptPath + FileName);
Writeln(ReadINI(Section, KeyName, ScriptPath + FileName);
end.
procedure DeleteINI(const Section, KeyName, FileName: string);
The following example deletes the specific line inside the specified INI file.
program DeleteINIExample;
begin
DeleteINI('Section', Key, File);
end;
function ExtractFileExt(const FileName: string): string;');
Returns the file extension from file Filename.