Вопрос по луашке

SomaGnoma

Известный
Автор темы
442
152
Версия MoonLoader
.026-beta
Драсте, как можно узнать файлы в папке?
Пример: я
Есть папка GTA/moonloader/gayporn
А в ней есть два файлика:
GTA/moonloader/gayporn/Billy.txt
GTA/moonloader/gayporn/Van.txt

Суть:
Вывести названия файликов в папке.
----------#-1(1)@)@/19181(1
И ещё вопросик:
Как можно читать по строчкам текстовый файлик через io.?
Есть файл:
Govnina.txt
И в нем:
Чмошник
Сосун
Узбек
Негр
И нужно вывести 2 строчку, то есть "Сосун"
 
Решение
1.
Lua:
function scanFiles(path, type)
    local TEMP = {}
    local search, file = findFirstFile(path.."\\"..type)
    local count = 0
    if file ~= '.' and file ~= '..' then table.insert(TEMP, file)  end
    while file do
        count = count+1
        file = findNextFile(search)
        if file ~= '.' and file ~= '..' then table.insert(TEMP, file)  end 
    end
    return TEMP
end
Пример:
Lua:
local list = scanFiles(getWorkingDirectory()..'\\gayporn', '*.txt')
for i = 1, #list do
    sampAddChatMessage('Найден файл '..list[i], -1)
end

2.
Lua:
function getFileLineText(file, lineIndex)
    local l = 0
    for line in io.lines(file) do
        l = l + 1
        if l == lineIndex then
            return line
        end
    end...

chapo

🫡 В армии с 17.10.2023. В ЛС НЕ ОТВЕЧАЮ
Друг
8,777
11,224
1.
Lua:
function scanFiles(path, type)
    local TEMP = {}
    local search, file = findFirstFile(path.."\\"..type)
    local count = 0
    if file ~= '.' and file ~= '..' then table.insert(TEMP, file)  end
    while file do
        count = count+1
        file = findNextFile(search)
        if file ~= '.' and file ~= '..' then table.insert(TEMP, file)  end 
    end
    return TEMP
end
Пример:
Lua:
local list = scanFiles(getWorkingDirectory()..'\\gayporn', '*.txt')
for i = 1, #list do
    sampAddChatMessage('Найден файл '..list[i], -1)
end

2.
Lua:
function getFileLineText(file, lineIndex)
    local l = 0
    for line in io.lines(file) do
        l = l + 1
        if l == lineIndex then
            return line
        end
    end
end
Пример:
Lua:
sampAddChatMessage(getFileLineText(getWorkingDirectory()..'\\gayporn\\Govnina.txt', 2), -1)
 
  • Нравится
Реакции: SomaGnoma