38 lines
854 B
Lua
38 lines
854 B
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 ~= 0 then
|
||
|
game.Log(tostring(FileSys) .. ".getcwd() : popen failed executing " .. tostring(err), game.LOGGER_ERROR)
|
||
|
return nil
|
||
|
end
|
||
|
|
||
|
cwd = pfile:read()
|
||
|
pfile:close()
|
||
|
|
||
|
return cwd
|
||
|
end
|
||
|
|
||
|
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 nil
|
||
|
end
|
||
|
|
||
|
for filename in pfile:lines() do
|
||
|
i = i + 1
|
||
|
t[i] = filename
|
||
|
end
|
||
|
|
||
|
pfile:close()
|
||
|
|
||
|
return t
|
||
|
end
|