isdir

function isdir( path ) --> res

Description

Is it a path to a directory.

Parameters

path

Path that should be checked.

Return Values

res

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

Code

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

return isdir

Examples

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

-- setup
res, err = mkdirtree{
   [ "tmpdir" ] = {
      [ "tmpfile.txt" ] = ""
   }
}

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

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

t()

See also