Lua獲取文件長度和判斷文件是否存在函數(shù)

字號:


    這篇文章主要介紹了Lua獲取文件長度和判斷文件是否存在函數(shù)分享,需要的朋友可以參考下
    獲得文件長度
    代碼如下:
    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