Lua获取文件长度和判断文件是否存在函数分享
- 作者: ZCG曳
- 来源: 51数据库
- 2020-08-09
这篇文章主要介绍了Lua获取文件长度和判断文件是否存在函数分享,需要的朋友可以参考下
function length_of_file(filename)
local fh = assert(io.open(filename, "rb"))
local len = assert(fh:seek("end"))
fh:close()
return len
end
判断文件是否存在
function file_exists(path)
local file = io.open(path, "rb")
if file then file:close() end
return file ~= nil
end
获得文件长度
复制代码 代码如下:
function length_of_file(filename)
local fh = assert(io.open(filename, "rb"))
local len = assert(fh:seek("end"))
fh:close()
return len
end
判断文件是否存在
复制代码 代码如下:
function file_exists(path)
local file = io.open(path, "rb")
if file then file:close() end
return file ~= nil
end
推荐阅读
