packages1/mfs/lib/mfs.lua
2021-01-01 19:41:57 +00:00

60 lines
867 B
Lua

local mfs={}
local cd=""
function mfs.setcd(x)
if fs.exists(x) and fs.isDir(x) then
cd=x
return true
else
return false,"No such directory "..x
end
end
function mfs.getcd()
return cd
end
function mfs.read(x)
local f=fs.open(cd.."/"..x,"r")
if not f then return nil end
local i=f.readAll()
f.close()
return i
end
function mfs.write(x,v)
local f=fs.open(cd.."/"..x,"w")
f.write(v)
f.close()
end
function mfs.mmkdir(x)
if not fs.exists(cd.."/"..x) then
fs.makeDir(cd.."/"..x)
end
end
function mfs.save(x,t)
mfs.write(x,textutils.serialize(t))
end
function mfs.load(x)
return textutils.unserialize(mfs.read(x) or "{}")
end
function mfs.rm(x)
fs.delete(cd.."/"..x)
end
function mfs.type(x)
if not fs.exists(cd.."/"..x) then
return "none"
end
if fs.isDir(cd.."/"..x) then
return "directory"
else
return "file"
end
end
return mfs