lua samp поиск файла в куче папок

Fellespe.

Участник
Автор темы
42
8
Версия MoonLoader
Другое
Как можно достать из этих папок определенный скрин по названию, например 21.36.38.093.jpg
1696619013240.png

С работой с папками не особо дружу в луа :(
 
Решение
Lua:
---@param path string directory
---@param ftype string|string[] file extension
---@return string[] files names
function getFilesInPath(path, ftype)
    assert(path, '"path" is required');
    -- assert(type(ftype) == 'table' or type(ftype) == 'string', '"ftype" must be a string or array of strings');
    local result = {};
    for _, thisType in ipairs(type(ftype) == 'table' and ftype or { ftype }) do
        local searchHandle, file = findFirstFile(path.."/"..thisType);
        table.insert(result, file)
        while file do file = findNextFile(searchHandle) table.insert(result, file) end
    end
    return result;
end
function findFileInFolders(startPath, target)
    local list = getFilesInPath(startPath, '*');
    for _, filename...

chapo

🫡 В армии с 17.10.2023. В ЛС НЕ ОТВЕЧАЮ
Друг
8,778
11,221
Lua:
---@param path string directory
---@param ftype string|string[] file extension
---@return string[] files names
function getFilesInPath(path, ftype)
    assert(path, '"path" is required');
    -- assert(type(ftype) == 'table' or type(ftype) == 'string', '"ftype" must be a string or array of strings');
    local result = {};
    for _, thisType in ipairs(type(ftype) == 'table' and ftype or { ftype }) do
        local searchHandle, file = findFirstFile(path.."/"..thisType);
        table.insert(result, file)
        while file do file = findNextFile(searchHandle) table.insert(result, file) end
    end
    return result;
end
function findFileInFolders(startPath, target)
    local list = getFilesInPath(startPath, '*');
    for _, filename in pairs(list) do
        if (#filename > 2) then
            local thisPath = ('%s\\%s'):format(startPath, filename);
            if (doesFileExist(('%s\\%s'):format(thisPath, target))) then
                return thisPath;
            end
        end
    end
end

print('OK', findFileInFolders('C:\\Users\\amids\\OneDrive\\Documents\\GTA San Andreas User Files\\SAMP\\arizona\\screens', '21.14.31.484.jpg'));
1696621778143.png

1696621670578.png