local io, os, error = io, os, error
local io, os, error = io, os, error
local file = {}
function file.exists(path)
local file = io.open(path, 'rb')
if file then
file:close()
end
return file ~= nil
end
Return the content of the file by reading the given path
and mode
.
path
is a string.mode
is a string.function file.read(path, mode)
mode = mode or '*a'
local file, err = io.open(path, 'rb')
if err then
error(err)
end
local content = file:read(mode)
file:close()
return content
end
Write to the file with the given path
, content
and mode
.
path
is a string.content
is a string.mode
is a string.function file.write(path, content, mode)
mode = mode or 'w'
local file, err = io.open(path, mode)
if err then
error(err)
end
file:write(content)
file:close()
end
Copy the file by reading the src
and writing it to the dest
.
src
is a string.dest
is a string.function file.copy(src, dest)
local content = file.read(src)
file.write(dest, content)
end
function file.move(src, dest)
os.rename(src, dest)
end
function file.remove(path)
os.remove(path)
end
return file