Difference between revisions of "Lua:getDirectoryList"
Jump to navigation
Jump to search
m |
|||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
[[Category:Lua]] | [[Category:Lua]] | ||
| − | '''function''' getDirectoryList(''Path'', | + | {{CodeBox|'''function''' getDirectoryList(''Path'', ''SearchSubDirs'') ''':''' table}} |
| − | Returns an indexed table containing | + | Returns an indexed table containing directory names. |
| + | |||
| + | The function lists directories inside the given path. When SearchSubDirs is true, subdirectories are searched recursively. | ||
===Function Parameters=== | ===Function Parameters=== | ||
| Line 12: | Line 14: | ||
|Path | |Path | ||
|String | |String | ||
| − | |The directory path to search. | + | |The directory path to search in. |
|- | |- | ||
|SearchSubDirs | |SearchSubDirs | ||
|Boolean (optional) | |Boolean (optional) | ||
| − | |If true, | + | |If true, subdirectories are searched recursively. |
|} | |} | ||
===Returns=== | ===Returns=== | ||
| − | Table — An indexed table | + | Table — An indexed table containing directory names. |
===Examples=== | ===Examples=== | ||
<pre> | <pre> | ||
| − | local | + | local directories = getDirectoryList("C:\\\\Temp") |
| − | for i, | + | |
| − | print( | + | for i = 1, #directories do |
| + | print(directories[i]) | ||
end | end | ||
| + | </pre> | ||
| + | |||
| + | <pre> | ||
| + | local directories = getDirectoryList("C:\\\\Temp", true) | ||
| + | |||
| + | print("Directories found: " .. tostring(#directories)) | ||
| + | |||
| + | for i = 1, #directories do | ||
| + | print(directories[i]) | ||
| + | end | ||
| + | </pre> | ||
| + | |||
| + | <pre> | ||
| + | local path = getTempFolder() | ||
| + | local directories = getDirectoryList(path) | ||
| − | + | for i, directory in ipairs(directories) do | |
| − | + | print(directory) | |
| − | for i, | ||
| − | print( | ||
end | end | ||
</pre> | </pre> | ||
| − | + | {{LuaSeeAlso}} | |
| − | |||
| − | |||
Latest revision as of 00:49, 25 June 2026
Returns an indexed table containing directory names.
The function lists directories inside the given path. When SearchSubDirs is true, subdirectories are searched recursively.
Function Parameters[edit]
| Parameter | Type | Description |
|---|---|---|
| Path | String | The directory path to search in. |
| SearchSubDirs | Boolean (optional) | If true, subdirectories are searched recursively. |
Returns[edit]
Table — An indexed table containing directory names.
Examples[edit]
local directories = getDirectoryList("C:\\\\Temp")
for i = 1, #directories do
print(directories[i])
end
local directories = getDirectoryList("C:\\\\Temp", true)
print("Directories found: " .. tostring(#directories))
for i = 1, #directories do
print(directories[i])
end
local path = getTempFolder() local directories = getDirectoryList(path) for i, directory in ipairs(directories) do print(directory) end