1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-11-25 10:42:20 -05:00
Simba/Doc/sphinx/scriptref/files.rst

216 lines
4.1 KiB
ReStructuredText
Raw Normal View History

2010-06-12 12:18:19 -04:00
Working with Files
==================
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.
2010-09-09 10:40:57 -04:00
CreateFile
----------
.. code-block:: pascal
function CreateFile(const Path: string): Integer;
Create a file with *Path*. Raturns -1 on failure, otherwise returns the handle
to the file.
2010-09-09 10:40:57 -04:00
OpenFile
--------
.. code-block:: pascal
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.
2010-09-09 10:40:57 -04:00
RewriteFile
-----------
.. code-block:: pascal
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.
2010-09-09 10:40:57 -04:00
AppendFile
----------
.. code-block:: pascal
function AppendFile(const Path: string): Integer;
Opens file for writing (appending).
Returns -1 on failure, otherwise returns the handle to the file.
2010-09-09 10:40:57 -04:00
CloseFile
---------
.. code-block:: pascal
procedure CloseFile(FileNum: Integer);
Close the file defined by *FileNum*. Never forget to close your files!
2010-09-09 10:40:57 -04:00
EndOfFile
---------
.. code-block:: pascal
function EndOfFile(FileNum: Integer): Boolean;
Returns true if the end of the file has been reached.
2010-09-09 10:40:57 -04:00
FileSize
--------
.. code-block:: pascal
function FileSize(FileNum: Integer): LongInt;
Returns the file size in characters.
2010-09-09 10:40:57 -04:00
ReadFileString
--------------
.. code-block:: pascal
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*.
2010-09-09 10:40:57 -04:00
WriteFileString
---------------
.. code-block:: pascal
function WriteFileString(FileNum: Integer; s: string): Boolean;
Writes *s* to file *FileNum*. Returns false on failure.
2010-09-09 10:40:57 -04:00
SetFileCharPointer
------------------
.. code-block:: pascal
function SetFileCharPointer(FileNum, cChars, Origin: Integer): Integer;
*Seek* through the file. Set the cursor to *cChars* from *Origin*.
Origin can be any of these:
.. code-block:: pascal
{ File seek origins }
FsFromBeginning = 0;
FsFromCurrent = 1;
FsFromEnd = 2;
2010-09-09 10:40:57 -04:00
FilePointerPos
--------------
.. code-block:: pascal
function FilePointerPos(FileNum: Integer): Integer;
Returns the position of the *cursur* in the file.
(What character # you are at)
2010-09-09 10:40:57 -04:00
DirectoryExists
---------------
.. code-block:: pascal
function DirectoryExists(const DirectoryName : string ) : Boolean;
Returns true if the directory exists.
2010-09-09 10:40:57 -04:00
CreateDirectory
---------------
.. code-block:: pascal
function CreateDirectory(const DirectoryName : string) : boolean;
Creates a directory. Returns true on success.
2010-09-09 10:40:57 -04:00
FileExists
-----------
.. code-block:: pascal
function FileExists (const FileName : string ) : Boolean;
Returns true if the file exists.
2010-09-09 10:40:57 -04:00
ForceDirectories
----------------
.. code-block:: pascal
function ForceDirectories(const dir : string) : boolean;
Creates multiple *nested* directories. Returns true on success.
2010-09-09 10:40:57 -04:00
GetFiles
--------
.. code-block:: pascal
function GetFiles(const Path, Ext : string) : TStringArray;
Returns the files in the directory defined by *Path* with extension *Ext*.
2010-09-09 10:40:57 -04:00
GetDirectories
--------------
.. code-block:: pascal
function GetDirectories(const path : string) : TStringArray;
Returns the directories in *path*.
2010-09-09 10:40:57 -04:00
WriteINI
--------
.. code-block:: pascal
procedure WriteINI(const Section, KeyName, NewString, FileName: string);
ReadINI
-------
.. code-block:: pascal
function ReadINI(const Section, KeyName, FileName: string): string;
DeleteINI
---------
.. code-block:: pascal
procedure DeleteINI(const Section, KeyName, FileName: string);
ExtractFileExt
--------------
.. code-block:: pascal
function ExtractFileExt(const FileName: string): string;');
Returns the file extension from file *Filename*.