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中的loadfile、dofile、require詳解
這篇文章主要介紹了Lua中的loadfile、dofile、require詳解,本文分別用實例講解它的用法和特點等內容,需要的朋友可以參考下2014-09-09