isreadable

isreadable

function isreadable( path ) --> res

Description

Is it a path to a readable file.

Parameters

path

Path to a file that should be checked.

Return Values

res

true if the path is to a readable file, otherwise false.

Code

--ZFUNC-isreadable-v0
local function isreadable( path ) --> res
   local f = io.open(path, "r" )
   if not f then return false end
   f:close()
   return true
end

return isreadable

Examples

local t = require "taptest"
local isreadable = require "isreadable"

io.open( "isreadable.txt", "wb" ):close()
t( isreadable( "isreadable.txt" ), true )

os.remove( "isreadable.txt" )
t( isreadable( "isreadable.txt" ), false )

t()