2010-06-12 12:18:19 -04:00
|
|
|
Working with Files
|
|
|
|
==================
|
|
|
|
|
2011-01-05 09:09:30 -05:00
|
|
|
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;
|
|
|
|
|
2011-01-05 09:09:30 -05:00
|
|
|
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;
|
|
|
|
|
2011-01-05 09:09:30 -05:00
|
|
|
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;
|
|
|
|
|
2011-01-09 08:01:53 -05:00
|
|
|
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;
|
|
|
|
|
2011-01-09 08:01:53 -05:00
|
|
|
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);
|
|
|
|
|
2011-01-09 08:01:53 -05:00
|
|
|
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;
|
|
|
|
|
2011-01-09 08:01:53 -05:00
|
|
|
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;
|
|
|
|
|
2011-01-09 08:01:53 -05:00
|
|
|
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;
|
|
|
|
|
2011-01-09 08:01:53 -05:00
|
|
|
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;
|
|
|
|
|
2011-01-09 08:01:53 -05:00
|
|
|
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;
|
|
|
|
|
2011-01-09 08:01:53 -05:00
|
|
|
*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;
|
|
|
|
|
2011-01-09 08:01:53 -05:00
|
|
|
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;
|
|
|
|
|
2011-01-09 08:01:53 -05:00
|
|
|
Returns true if the directory exists.
|
2010-09-09 10:40:57 -04:00
|
|
|
|
|
|
|
CreateDirectory
|
|
|
|
---------------
|
|
|
|
|
|
|
|
.. code-block:: pascal
|
|
|
|
|
|
|
|
function CreateDirectory(const DirectoryName : string) : boolean;
|
|
|
|
|
2011-01-09 08:01:53 -05:00
|
|
|
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;
|
|
|
|
|
2011-01-09 08:01:53 -05:00
|
|
|
Returns true if the file exists.
|
|
|
|
|
2010-09-09 10:40:57 -04:00
|
|
|
|
|
|
|
ForceDirectories
|
|
|
|
----------------
|
|
|
|
|
|
|
|
.. code-block:: pascal
|
|
|
|
|
|
|
|
function ForceDirectories(const dir : string) : boolean;
|
|
|
|
|
2011-01-09 08:01:53 -05:00
|
|
|
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;
|
|
|
|
|
2011-01-09 08:01:53 -05:00
|
|
|
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;
|
|
|
|
|
2011-01-09 08:01:53 -05:00
|
|
|
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;');
|
|
|
|
|
2011-01-09 08:01:53 -05:00
|
|
|
Returns the file extension from file *Filename*.
|