2023-08-19 04:25:27 +02:00
|
|
|
---@diagnostic disable: duplicate-set-field
|
|
|
|
require("core.platform.filesys")
|
2022-08-11 03:15:01 +02:00
|
|
|
|
2023-08-19 04:25:27 +02:00
|
|
|
filesys.sep = "/"
|
2022-08-11 03:15:01 +02:00
|
|
|
|
2023-08-19 04:25:27 +02:00
|
|
|
---Return a string representing the current working directory
|
|
|
|
---@return string
|
|
|
|
function filesys.getcwd()
|
2022-08-11 03:15:01 +02:00
|
|
|
local cwd, popen = "", io.popen
|
|
|
|
local pfile, err = popen("pwd")
|
|
|
|
|
|
|
|
if not pfile or err ~= 0 then
|
2023-08-19 04:25:27 +02:00
|
|
|
game.Log(tostring(filesys) .. ".getcwd() : popen failed executing " .. tostring(err), game.LOGGER_ERROR)
|
|
|
|
return ""
|
2022-08-11 03:15:01 +02:00
|
|
|
end
|
|
|
|
|
2023-08-19 04:25:27 +02:00
|
|
|
cwd = pfile:read() or ""
|
|
|
|
|
2022-08-11 03:15:01 +02:00
|
|
|
pfile:close()
|
|
|
|
|
|
|
|
return cwd
|
|
|
|
end
|
|
|
|
|
2023-08-19 04:25:27 +02:00
|
|
|
---Return a list of files and directory names in `path`
|
|
|
|
---@param path string
|
|
|
|
---@return string[]
|
|
|
|
function filesys.scandir(path)
|
2022-08-11 03:15:01 +02:00
|
|
|
local i, t, popen = 0, {}, io.popen
|
|
|
|
local pfile, err = popen('find "' .. path .. '" -maxdepth 1 -print0')
|
|
|
|
|
|
|
|
if not pfile or err ~= 0 then
|
2023-08-19 04:25:27 +02:00
|
|
|
game.Log(tostring(filesys) .. ".scandir() : popen failed executing " .. tostring(err), game.LOGGER_ERROR)
|
|
|
|
return {}
|
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
|