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( "tapered" )
local isfile = require( "isfile" )
-- util functions
local mkdirtree = require( "mkdirtree" )
local rmdirtree = require( "rmdirtree" )

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

-- test
t.nok( isfile( "tmpdir" ) )
t.ok( isfile( "tmpdir/tmpfile.txt" ) )

-- teardown
t.ok( rmdirtree( "tmpdir" ) )

t.done()