Added current directory and rm to mfs

This commit is contained in:
v 2020-12-29 09:45:24 +00:00
parent d46df8884b
commit d3c46ace5f
2 changed files with 24 additions and 7 deletions

View File

@ -1,7 +1,20 @@
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(x,"r")
local f=fs.open(cd.."/"..x,"r")
if not f then return nil end
local i=f.readAll()
f.close()
@ -9,23 +22,27 @@ function mfs.read(x)
end
function mfs.write(x,v)
local f=fs.open(x,"w")
local f=fs.open(cd.."/"..x,"w")
f.write(v)
f.close()
end
function mfs.mmkdir(x)
if not fs.exists(x) then
fs.makeDir(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))
mfs.write(cd.."/"..x,textutils.serialize(t))
end
function mfs.load(x)
return textutils.unserialize(mfs.read(x) or "{}")
return textutils.unserialize(mfs.read(cd.."/"..x) or "{}")
end
function mfs.rm(x)
fs.delete(cd.."/"..x)
end
return mfs

View File

@ -1,5 +1,5 @@
{
["version"] = "0.1.2",
["version"] = "0.1.3",
["dependencies"] = {
},