pathListDir | Multi Theft Auto: Wiki Skip to content

pathListDir

Client-side
Server-side
Shared

This page is incomplete! Help wanted!

Please finish this page using the corresponding Old Wiki article.
Go to Contribution guidelines for more information.


Reads a specified directory and returns all entries inside of it. These entries can be file or folder names.

Note

Listing other resource directory can be done by passing ":resourceName/." For listing current resource (the one where code is executed), you can pass either "" or ":currentResourceName/." (preferably use first approach, because the latter will require removing this part, once result is ready)

Syntax

pathListDir ( )

Code Examples

shared

This example loads all models from a certain directory

-- from https://gist.github.com/kgriffs/124aae3ac80eefe57199451b823c24ec
local function stringEndsWith(str, ending)
return ending == "" or str:sub(-#ending) == ending
end
-- get all files from a models directory that exists in the resource root folder (resources/ResourceName)
-- and load them into the game
addEventHandler('onClientResourceStart', resourceRoot, function()
local entries = pathListDir('models') or {}
for _, fileOrFolder in ipairs(entries) do
if pathIsFile(fileOrFolder) then
local file = fileOrFolder
local modelName = tonumber(file:sub(1, -5))
if modelName then
-- the full path to the file
local filePath = 'models/'..file
if stringEndsWith(file, '.col') then
local colData = engineLoadCOL(filePath)
if colData then
engineReplaceCOL(colData, modelName)
end
end
if stringEndsWith(file, '.txd') then
local txdData = engineLoadTXD(filePath)
if txdData then
engineImportTXD(txdData, modelName)
end
end
if stringEndsWith(file, '.dff') then
local dffData = engineLoadDFF(filePath)
if dffData then
engineReplaceModel(dffData, modelName)
end
end
end
end
end
end, false)

See Also

Path Functions