isfile

function isfile( path ) --> res

Description

Is it a path to a file.

Parameters

path

Path that should be checked.

Return Values

res

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

Code

local lfs = require( "lfs" ) --ZREQ-lfs
--ZFUNC-isfile-v1
local function isfile( path ) --> res
   local attr = lfs.attributes( path )
   if attr.mode == "file" then return true
   else return false end
end

return isfile

Examples

local t = require( "taptest" )
local isfile = require( "isfile" )
local mkdirtree = require( "mkdirtree" )
local rmdirtree = require( "rmdirtree" )

-- setup
t( mkdirtree{
   [ "tmpdir" ] = {
      [ "tmpfile.txt" ] = ""
   }
}, true )

-- test
t( isfile( "tmpdir" ), false )
t( isfile( "tmpdir/tmpfile.txt" ), true )

-- teardown
t( rmdirtree( "tmpdir" ), true )

t()