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

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

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

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

t.done()

See also