PathListDir

From Multi Theft Auto: Wiki
Revision as of 11:20, 26 May 2024 by Tracer (talk | contribs) (Fixed `See also` section)
Jump to navigation Jump to search

BETA: NEW FEATURE (BUILD: 1.6.0 r22470)

Reads a specified directory and returns all entries inside of it.

Syntax

table pathListDir ( string path )

OOP Syntax Help! I don't understand this!

Method: path:listDir(...)


Required Arguments

  • path: A string containing a path you want to get entries from

Returns

Returns table with all entries in a specified directory.

Example

Click to collapse [-]
Client

This example loads all models from a certain directory

addEventHandler('onClientResourceStart', resourceRoot, function()
    -- get all files from a models directory that exists in the resource root folder (resources/ResourceName)
    local files = pathListDir('/models')
    for _,file in ipairs(files) do
        local filePath = 'models/'..file
        local modelName = tonumber(file:sub(1, -5)) or 0

        if file:endsWith('.col') then
            local colData = engineLoadCOL('models/'..file)

            if colData then
                engineReplaceCOL(colData, modelName)
            end
        end
        if file:endsWith('.txd') then
            local txdData = engineLoadTXD('models/'..file)

            if txdData then
                engineImportTXD(txdData, modelName)
            end
        end
        if file:endsWith('.dff') then
            local dffData = engineLoadDFF('models/'..file)

            if dffData then
                engineReplaceModel(dffData, modelName)
            end
        end
    end
end)

See Also