Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- makeFS = function(root)
- root = root or ""
- local ciw = function(dir) --'check if within' the root directory
- if fs.isReadOnly(dir) then
- return true
- else
- return string.find("///"..dir, "///"..root) and true or false
- end
- end
- local nonexistdir = function()
- local number
- while true do
- for a = 1, 512 do
- thedir = "dir"..tostring(math.random(1,9999999999999))
- if not fs.exists(thedir) then
- return thedir
- end
- end
- sleep(0)
- end
- end
- local nfs = {}
- nfs.combine = fs.combine
- nfs.getDrive = function(dir)
- if not ciw(dir) then dir = nonexistdir() end
- return fs.getDrive(dir)
- end
- nfs.getName = function(dir)
- if not ciw(dir) then dir = nonexistdir() end
- return fs.getName(dir)
- end
- nfs.getFreeSpace = function(dir)
- if not ciw(dir) then dir = nonexistdir() end
- return fs.getFreeSpace(dir and nfs.combine(root,dir) or nil)
- end
- nfs.getSize = function(dir)
- if not ciw(dir) then dir = nonexistdir() end
- return fs.getSize(nfs.combine(root,dir))
- end
- nfs.list = function(dir)
- if not ciw(dir) then dir = nonexistdir() end
- return fs.list(nfs.combine(root,dir))
- end
- nfs.exists = function(dir)
- if not ciw(dir) then dir = nonexistdir() end
- return fs.exists(nfs.combine(root,dir))
- end
- nfs.isDir = function(dir)
- if not ciw(dir) then dir = nonexistdir() end
- return fs.isDir(nfs.combine(root,dir))
- end
- nfs.isReadOnly = function(dir)
- if not ciw(dir) then dir = nonexistdir() end
- return fs.isReadOnly(nfs.combine(root,dir))
- end
- nfs.makeDir = function(dir)
- if not ciw(dir) then dir = nonexistdir() end
- return fs.makeDir(nfs.combine(root,dir))
- end
- nfs.move = function(from,to)
- if not ciw(from) then from = nonexistdir() end
- if not ciw(to) then to = nonexistdir() end
- return fs.move(nfs.combine(root,from),nfs.combine(root,to))
- end
- nfs.copy = function(from,to)
- if not ciw(from) then from = nonexistdir() end
- if not ciw(to) then to = nonexistdir() end
- return fs.copy(nfs.combine(root,from),nfs.combine(root,to))
- end
- nfs.delete = function(dir)
- if not ciw(dir) then dir = nonexistdir() end
- return fs.delete(nfs.combine(root,dir))
- end
- nfs.open = function(file,mode)
- if not ciw(file) then file = nonexistdir() end
- return fs.open(nfs.combine(root,file),mode)
- end
- nfs.find = function(dir)
- if not ciw(dir) then dir = nonexistdir() end
- return fs.find(dir and nfs.combine(root,dir) or nil)
- end
- nfs.getDir = function(dir)
- if not ciw(dir) then dir = nonexistdir() end
- return fs.getDir(nfs.combine(root,dir))
- end
- nfs.complete = function(name,path,inclFiles,inclSlashes)
- if not ciw(path) then path = nonexistdir() end
- return fs.complete(name,nfs.combine(root,path),inclFiles,inclSlashes)
- end
- return nfs
- end
Add Comment
Please, Sign In to add comment