Modules/FileSystem/translator/getFiles: Difference between revisions
Jump to navigation
Jump to search
(Created page with "__NOTOC__ This function returns a list of all files that are found under the wild-card and directory parameters. It is similar to scanDir but returns files only. ==Syntax== <syntaxhighlight lang="lua"> table translator:getFiles ( string dirPath, string wildcard, bool recursive ) </syntaxhighlight> ==Arguments== *'''dirPath:''' a path to the directory the scan shall take place or start in *'''wildcard:''' glob-style wild-card fo...") |
No edit summary |
||
| Line 1: | Line 1: | ||
<pageclass class="#3c82c8" subcaption="Translator function"></pageclass> | |||
__NOTOC__ | __NOTOC__ | ||
This function returns a list of all files that are found under the wild-card and directory parameters. It is similar to [[MTA:Eir/FileSystem/translator/scanDir|scanDir]] but returns files only. | This function returns a list of all files that are found under the wild-card and directory parameters. It is similar to [[MTA:Eir/FileSystem/translator/scanDir|scanDir]] but returns files only. | ||
Latest revision as of 03:31, 23 January 2022
This function returns a list of all files that are found under the wild-card and directory parameters. It is similar to scanDir but returns files only.
Syntax
table translator:getFiles ( string dirPath, string wildcard, bool recursive )
Arguments
- dirPath: a path to the directory the scan shall take place or start in
- wildcard: glob-style wild-card for filename matching; every filename that matches the wild-card is returned
- 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 file 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." );