isleafdir
function isleafdir( path ) --> res
Description
Checks if path directs to a directory without sub directories.
Parameters
- path
-
Path that should be checked.
Return Values
- res
-
true if the path is to directory without sub directories, otherwise false.
Code
local lfs = require( "lfs" ) --ZREQ-lfs --ZFUNC-isleafdir-v1 local function isleafdir( path ) --> res --ZFUNC-isdodd-v1 local function isdodd( e ) if e == "." or e == ".." then return true end return false end local mode = lfs.attributes( path, "mode" ) if mode ~= "directory" then return false end for entry in lfs.dir( path ) do local entrypath = path.."/"..entry local mode = lfs.attributes( entrypath, "mode" ) if mode == "directory" and not isdodd( entry ) then return false end end return true end return isleafdir
Examples
local t = require( "taptest" ) local isleafdir = require( "isleafdir" ) local mkdirtree = require( "mkdirtree" ) local rmdirtree = require( "rmdirtree" ) -- setup t( mkdirtree{ [ "middir" ] = { [ "leafdir" ] = { [ "tmpfile.txt" ] = "" } } }, true ) -- test t( isleafdir( "middir/leafdir" ), true ) t( isleafdir( "middir" ), false ) -- teardown t( rmdirtree( "middir" ), true ) t()