Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local M = {}
- function M.readfile(path, mode)
- mode = mode or 'rb'
- local file, err = io.open(path, mode)
- if not file then return nil, err end
- local data = file:read'*all'
- file:close()
- return data
- end
- function M.writefile(path, data, mode)
- mode = mode or 'wb'
- local file, err = io.open(path, mode)
- if not file then return nil, err end
- file:write(data)
- return file:close()
- end
- function M.appendfile(path, data, mode)
- mode = mode or 'a'
- local file, err = io.open(path, mode)
- if not file then return nil, err end
- file:write(data)
- return file:close()
- end
- function M.isFile(path)
- local file = io.open(path, "r")
- return file and file:close() or false
- end
- function M.isDirectory(path)
- local file, err = io.open(path, "r")
- return err == 'Permission denied' or file and not file:close()
- end
- M.path = {}
- function M.path.normalslashes(path)
- return string.gsub(path, "\\", "/")
- end
- function M.path.endslash(path)
- if string.sub(path, #path-1) ~= "/" then
- return p .. "/"
- else
- return p
- end
- end
- function M.path.leaf(path)
- path = M.path.normalslashes(path)
- local a = 1
- local last = path
- while path do
- path = string.find(path, "/", a+1)
- if path then
- last = string.sub(path, a+1)
- end
- end
- return last
- end
- return M
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement