49 lines
716 B
Lua
49 lines
716 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(cd.."/"..x) or "{}")
|
|
end
|
|
|
|
function mfs.rm(x)
|
|
fs.delete(cd.."/"..x)
|
|
end
|
|
|
|
return mfs
|