From Multi Theft Auto: Wiki

This function loops through all translator filesystem entries that are captured by the wildcard and the directory specifier. The wildcard is glob-style and supports * and ? modifiers. The scan can be made recursive to enter every directory it finds, so that files and folders of a whole directory tree are captured. This function is used to process filesystem objects inside of directories without having to add the filenames into a configuration file. This greatly increases flexibility when processing files. Other than scanDirEx, this function returns a table of directories and files.


table translator.scanDir ( string dirPath, string wildcard, bool recursive )


  • dirPath: a path to the directory the scan shall take place or start in
  • wildcard: glob-style wild-card for filename matching; every filename that matches the wild-card is returned
  • recursive: a boolean that specifies whether the whole directory tree at dirPath should be included into the scan


This function returns a table consisting of all directories and all matching file entries which were found during the scan. It returns false if dirPath is an invalid path specifier for the translator.


Click to collapse [-]

This snippet outputs the count of directories and files in a specified directory relative to the resource instance root.

-- Get a handle to the resource instance directory.
local resRoot = fileCreateTranslator( "/" );

-- Function that returns whether the given path is a directory path.
local function isDirectoryPath( path )
   local lastChar = string.sub( path, #path, #path );

   return ( lastChar == "/" ) or ( lastChar == "\\" );

local function getFilesystemObjectCounts( path )
    local fileCount = 0;
    local dirCount = 0;

    -- Get a list of all fs objects.
    local fsObjects =
            path, -- scan anywhere the script wants us to
            "*", -- include all files
            false -- scan the specified directory only

    -- Loop through all object names to set up the counts.
    -- An object can either be a directory or a file.
    for m,n in ipairs(fsObjects) do
        if ( isDirectoryPath( n ) ) then
            dirCount = dirCount + 1;
            fileCount = fileCount + 1;

    -- Return the counts.
    return fileCount, dirCount;

-- Output the filesystem object counts for the resource instance root.
local fileCount, dirCount = getFilesystemObjectCounts( "/" );

outputChatBox( "found " .. fileCount .. " files and " .. dirCount .. " directories in the resource folder root." );

FileSystem Translator Functions