MTA:Eir/FileSystem/translator/getDirs: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
mNo edit summary |
||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
This function returns a list of all directories that are found under the | This function returns a list of all directories that are found under the directory path. It is similar to [[MTA:Eir/FileSystem/translator/scanDir|scanDir]] but returns directories only. | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
table translator | table translator:getDirs ( string dirPath, bool recursive ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
==Arguments== | ==Arguments== | ||
*'''dirPath:''' a path to the directory the scan shall take place or start in | *'''dirPath:''' a path to the directory the scan shall take place or start in | ||
*'''recursive:''' a boolean that specifies whether the whole directory tree at dirPath should be included into the scan | *'''recursive:''' a boolean that specifies whether the whole directory tree at dirPath should be included into the scan | ||
Line 27: | Line 26: | ||
-- Query the counts. | -- Query the counts. | ||
fileCount = #getFiles( path, "*", false ); | fileCount = #resRoot:getFiles( path, "*", false ); | ||
dirCount = #getDirs( path | dirCount = #resRoot:getDirs( path, false ); | ||
-- Return the counts. | -- Return the counts. |
Latest revision as of 23:30, 16 January 2022
This function returns a list of all directories that are found under the directory path. It is similar to scanDir but returns directories only.
Syntax
table translator:getDirs ( string dirPath, bool recursive )
Arguments
- dirPath: a path to the directory the scan shall take place or start in
- recursive: a boolean that specifies whether the whole directory tree at dirPath should be included into the scan
Returns
This function returns a table of all matching directory entries for the performed scan. It returns false if dirPath is not a valid directory target for the translator.
Example
Click to collapse [-]
ClientThis snippet is yet another alternative to output the count of directories and files in a folder.
-- Get a handle to the resource instance directory. local resRoot = fileCreateTranslator( "/" ); local function getFilesystemObjectCounts( path ) local fileCount = 0; local dirCount = 0; -- Query the counts. fileCount = #resRoot:getFiles( path, "*", false ); dirCount = #resRoot:getDirs( path, false ); -- Return the counts. return fileCount, dirCount; end -- Output the filesystem object counts for the resource instance root. local fileCount, dirCount = getFilesystemObjectCounts( "/" ); outputChatBox( "found " .. fileCount .. " files and " .. dirCount .. " directories in the resource folder root." );