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

45 lines
1.0 KiB
Lua

---@diagnostic disable: duplicate-set-field
require("core.platform.filesys")
filesys.sep = "/"
---Return a string representing the current working directory
---@return string
function filesys.getcwd()
local cwd, popen = "", io.popen
local pfile, err = popen("pwd")
if not pfile or err ~= 0 then
game.Log(tostring(filesys) .. ".getcwd() : popen failed executing " .. tostring(err), game.LOGGER_ERROR)
return ""
end
cwd = pfile:read() or ""
pfile:close()
return cwd
end
---Return a list of files and directory names in `path`
---@param path string
---@return string[]
function filesys.scandir(path)
local i, t, popen = 0, {}, io.popen
local pfile, err = popen('find "' .. path .. '" -maxdepth 1 -print0')
if not pfile or err ~= 0 then
game.Log(tostring(filesys) .. ".scandir() : popen failed executing " .. tostring(err), game.LOGGER_ERROR)
return {}
end
for filename in pfile:lines() do
i = i + 1
t[i] = filename
end
pfile:close()
return t
end