2022-08-11 03:15:01 +02:00
|
|
|
local FileSys = require "api.platform.filesys_impl"
|
|
|
|
|
|
|
|
FileSys.sep = "/"
|
|
|
|
|
|
|
|
function FileSys.getcwd()
|
|
|
|
local cwd, popen = "", io.popen
|
|
|
|
local pfile, err = popen("pwd")
|
|
|
|
|
2024-02-02 02:27:05 +01:00
|
|
|
if not pfile or err then
|
|
|
|
game.Log(FileSys.__name .. ".getcwd() : popen failed executing " .. tostring(err), game.LOGGER_ERROR)
|
|
|
|
|
|
|
|
if pfile then
|
|
|
|
pfile:close()
|
|
|
|
end
|
|
|
|
|
|
|
|
return nil, err
|
2022-08-11 03:15:01 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
cwd = pfile:read()
|
|
|
|
pfile:close()
|
|
|
|
|
|
|
|
return cwd
|
|
|
|
end
|
|
|
|
|
|
|
|
function FileSys.scandir(path)
|
2024-02-02 02:27:05 +01:00
|
|
|
if not FileSys.exists(path) then
|
|
|
|
return nil, "Incorrect or non-existent path"
|
|
|
|
end
|
|
|
|
|
2022-08-11 03:15:01 +02:00
|
|
|
local i, t, popen = 0, {}, io.popen
|
|
|
|
local pfile, err = popen('find "' .. path .. '" -maxdepth 1 -print0')
|
|
|
|
|
2024-02-02 02:27:05 +01:00
|
|
|
if not pfile or err then
|
|
|
|
game.Log(FileSys.__name .. ".scandir() : popen failed executing " .. tostring(err), game.LOGGER_ERROR)
|
|
|
|
|
|
|
|
if pfile then
|
|
|
|
pfile:close()
|
|
|
|
end
|
|
|
|
|
|
|
|
return nil, err
|
2022-08-11 03:15:01 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
for filename in pfile:lines() do
|
|
|
|
i = i + 1
|
|
|
|
t[i] = filename
|
|
|
|
end
|
|
|
|
|
|
|
|
pfile:close()
|
|
|
|
|
|
|
|
return t
|
|
|
|
end
|