ExperimentalGear/scripts/api/platform/linux/filesys.lua

52 lines
1.0 KiB
Lua

local FileSys = require "api.platform.filesys_impl"
FileSys.sep = "/"
function FileSys.getcwd()
local cwd, popen = "", io.popen
local pfile, err = popen("pwd")
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
end
cwd = pfile:read()
pfile:close()
return cwd
end
function FileSys.scandir(path)
if not FileSys.exists(path) then
return nil, "Incorrect or non-existent path"
end
local i, t, popen = 0, {}, io.popen
local pfile, err = popen('find "' .. path .. '" -maxdepth 1 -print0')
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
end
for filename in pfile:lines() do
i = i + 1
t[i] = filename
end
pfile:close()
return t
end