From Multi Theft Auto: Wiki

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.


translator fsnamespace.createTranslator( string rootPath )


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


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


Click to collapse [-]

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 = {};

-- Get a handle to the FileSystem module namespace.
local fsys = createFilesystemInterface();

-- Make sure we could obtain the module namespace.
if not ( fsys ) then
    outputDebugString( "could not obtain FileSystem module namespace" );
    return false;

-- Create a translator to the resource root.
local resRoot = fsys.createTranslator( "mods/deathmatch/resources/" .. getResourceName(resource) .. "/" );

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;

local function fileIterator( filePath )
    -- do nothing.

resRoot.scanDirEx( "/", "*", dirIterator, fileIterator, false );
Click to expand [+]

FileSystem Namespace Functions

FileSystem Translator Functions