pathIsDirectory
Client-side
Server-side
Shared
Manual Review Required
Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.
Checks if a specified path points to a directory.
OOP Syntax Help! I don't understand this!
- Method: path:isDirectory(...)
Syntax
bool pathIsDirectory ( string path )Required Arguments
- path: A string containing a path you want to check against
Returns
- bool: value
Returns true if the path points to a directory, false otherwise.
Code Examples
shared
This example lists entire structure of a folder
function string.startsWith(str, start) return string.sub(str, 1, #start) == startend
function string.repetition(what, n) local out = '' for i=1, n do out = out..what end return outend
local function getStructure(thePath) if thePath:startsWith('/') then thePath = thePath:sub(2) end
local structure = {} for _, entry in ipairs(pathListDir(thePath)) do local entryPath = thePath..'/'..entry if pathIsDirectory(entryPath) then structure[entry] = getStructure(entryPath) elseif pathIsFile(entryPath) then structure[entry] = false end end return structureend
local function printStructure(struct, tab) tab = tab or 0 for entry, isDir in pairs(struct) do iprint(string.repetition(' ',tab)..'- '..entry) if isDir then printStructure(isDir, tab + 2) end endend
printStructure(getStructure('.'))