MTA:Eir/FileSystem/translator/open

From Multi Theft Auto: Wiki
Revision as of 02:51, 29 January 2014 by The GTA (talk | contribs) (Created page with "__NOTOC__ This function opens a link to a file instance on a given MTA:Eir FileSystem translator. Using a file link, you can write and/or receive data from filesystems. ==Syntax...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This function opens a link to a file instance on a given MTA:Eir FileSystem translator. Using a file link, you can write and/or receive data from filesystems.

Syntax

file translator.open ( string filePath, string fileMode )

Arguments

  • filePath: the path to the file that should be opened
  • fileMode: an ANSI file mode descriptor (can be 'w', 'r' or 'a', with 'b' and/or '+' appended)

Returns

This function returns the FileSystem file class that can be used to retrieve or store data persistently. Returns false if the file failed to open for some reason.

Example

Click to collapse [-]
Client

This snippet attempts to open a file and output its contents inside of a CEGUI memo.

-- Get the screen size so we can scale the memo properly
local screenWidth, screenHeight = guiGetScreenSize();

-- Make the memo cover nearly the entire screen.
local myMemo = guiCreateMemo( 20, 20, screenWidth - 40, screenHeight - 40, "", false );

-- Read the contents of some file.
local fileContents = "";

local fileHandle = fileOpen( "someFile.txt", "rb" );

if ( fileHandle ) then
    fileContents = fileHandle.read( fileHandle.size() );

    -- Clean up our file handle.
    fileHandle.destroy();
end

-- Update the memo.
guiSetText( myMemo, fileContents );

FileSystem Translator Functions

FileSystem File Functions