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

47 lines
995 B
Lua
Raw Normal View History

local FileSys = require "api.platform.filesys_impl"
FileSys.sep = "\\"
function FileSys.getcwd()
local cwd, popen = "", io.popen
local pfile, err = popen("cd")
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
local baseNormpath = FileSys.normpath
function FileSys.normpath(path)
path = baseNormpath(path)
path = path:gsub("/", "\\")
return path
end
function FileSys.scandir(path)
local i, t, popen = 0, {}, io.popen
local pfile, err = popen('dir "' .. path .. '" /b /ad')
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