您现在的位置: 万盛学电脑网 >> 程序编程 >> 网络编程 >> 编程语言综合 >> 正文

Lua获取文件长度和判断文件是否存在函数

作者:佚名    责任编辑:admin    更新时间:2022-06-22

   这篇文章主要介绍了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