erdos/src/fs.lua

42 lines
842 B
Lua
Raw Normal View History

2022-02-16 18:53:37 +00:00
return function()
local lfs = love.filesystem
2022-02-21 18:29:51 +00:00
function fsPath(path)
local v = path:gsub(':', '/')
return v
end
2022-02-16 18:53:37 +00:00
function fsLs(path)
2022-02-21 18:29:51 +00:00
return lfs.getDirectoryItems(fsPath(path))
2022-02-16 18:53:37 +00:00
end
function fsHas(file)
if lfs.getInfo
2022-02-21 18:29:51 +00:00
then return not not lfs.getInfo(fsPath(file)) end
return lfs.exists(fsPath(file))
2022-02-16 18:53:37 +00:00
end
function fsInfo(file)
2022-02-21 18:29:51 +00:00
file = fsPath(file)
2022-02-16 18:53:37 +00:00
if lfs.getInfo
then return lfs.getInfo(file)
end
if not fsHas(file)
then return end
local info = {}
if lfs.isFile(file) then info.type = 'file'
elseif lfs.isDirectory(file) then info.type = 'directory'
elseif lfs.isSymlink(file) then info.type = 'symlink'
else info.type = 'other' end
info.size = lfs.getSize(file)
info.modtime = lfs.getLastModified(file)
return info
end
2022-02-21 18:29:51 +00:00
function fsRead(file)
return lfs.read(fsPath(file)), nil
end
2022-02-16 18:53:37 +00:00
end