Difference between revisions of "Lua:getDirectoryList"

From Cheat Engine
Jump to navigation Jump to search
m
 
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
'''function''' getDirectoryList(''Path'', [''SearchSubDirs'']) ''':''' Table
+
{{CodeBox|'''function''' getDirectoryList(''Path'', ''SearchSubDirs'') ''':''' table}}
  
Returns an indexed table containing the names of directories in the specified path.
+
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, searches subdirectories recursively. Default is false.
+
|If true, subdirectories are searched recursively.
 
|}
 
|}
  
 
===Returns===
 
===Returns===
Table — An indexed table with the names of directories found.
+
Table — An indexed table containing directory names.
  
 
===Examples===
 
===Examples===
 
<pre>
 
<pre>
local dirs = getDirectoryList(getAutorunPath())
+
local directories = getDirectoryList("C:\\\\Temp")
for i, name in ipairs(dirs) do
+
 
   print(name)
+
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)
  
-- Search recursively
+
for i, directory in ipairs(directories) do
local allDirs = getDirectoryList(getAutorunPath(), true)
+
   print(directory)
for i, name in ipairs(allDirs) do
 
   print(name)
 
 
end
 
end
 
</pre>
 
</pre>
  
== See also ==
+
{{LuaSeeAlso}}
* [[Lua:getFileList|getFileList]]
 

Latest revision as of 00:49, 25 June 2026

<> Lua API Reference

function getDirectoryList(Path, SearchSubDirs) : table

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

Main Pages

Core Lua documentation entry points

Lua
Script Engine