MTA:Eir/FileSystem/createTranslator

From Multi Theft Auto: Wiki
Revision as of 01:20, 29 January 2014 by The GTA (talk | contribs)
Jump to navigation Jump to search

This function creates a FileSystem translator. A FileSystem translator represents a directory on a real or virtual filesystem. Through translators you get access to the files that reside in their directory trees. The translator returned by this function usually represents an OS filesystem directory.

Syntax

translator fsnamespace.createTranslator( string rootPath )

Arguments

  • rootPath: the absolute path to the directory that you want access to.

Returns

This function returns the FileSystem translator that grants access to files in the requested directory.

Example

Click to collapse [-]
Client

This snippet links all directories inside of your resource instance folder using translators and lists them in a dictionary under their name.

-- Dictionary that will contain all directory links of our resource.
local dirs = {};

-- Create a translator to the resource root.
local resRoot = fileCreateTranslator( "/" );

local function dirIterator( dirPath )
    -- get the simple name of this directory.
    -- the simple name is the path relative to resRoot without the '/'
    local simpleName = resRoot.relPathRoot( dirPath );
    simpleName = string.sub( simpleName, 1, #simpleName - 1 );

    -- link this directory and set it into our dirs dictionary.
    -- we should always pass the absolute directory to this function.
    local translator = fileCreateTranslator( dirPath );

    dirs[simpleName] = translator;
end

local function fileIterator( filePath )
    -- do nothing.
    return;
end

resRoot.scanDirEx( "/", "*", dirIterator, fileIterator, false );

FileSystem Translator Functions