MTA:Eir/FileSystem/file/size

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

This function returns the size of a specific file/stream from beginning to end. Not all streams have to support this operation.

Syntax

int file:size ()

Returns

Returns the amount of bytes that this file/stream object is made of.

Example

Click to collapse [-]
Client

This snippet returns the contents of a file in a string buffer.

local function fileGetContents( path )
    -- Prevent a warning being output by checking for file existance first.
    if not ( fileExists( path ) ) then return false; end;

    -- Open the requested file.
    local theFile = fileOpen( path );

    if not ( theFile ) then return false; end;

    -- The the whole content of the file into a string buffer.
    local content = theFile:read( theFile:size() );

    -- Clean up the file handle.
    theFile:destroy();
    return content;
end

FileSystem File Functions