Lua获取文件长度和判断文件是否存在函数分享
更新时间:2015年04月20日 11:26:25 投稿:junjie
这篇文章主要介绍了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
相关文章
Lua的table库函数insert、remove、concat、sort详细介绍
这篇文章主要介绍了Lua的table库函数insert、remove、concat、sort详细介绍,本文分别给出了这几个函数的使用实例,需要的朋友可以参考下2015-04-04


最新评论