ListDir (list a directory)
ts
function ListDir(what, mask: string): DirListItem[];
The ListDir
function lists the contents of a directory in the local file system, and returns the results in a JavaScript array of DirListItem objects.
This function accepts either 1 or 2 parameters:
Parameter | Type | Requirement | Explanation |
---|---|---|---|
what | string | required | must be a valid and existent directory on a local file system |
mask | string | optional | file-mask (example: *.docx) to limit the scope of the returned results only to items matching such mask; if this parameter is not specified, the list will include all files in the directory |
Example
ts
{
// ...
// Acquire directory list
var dirList = cli.ListDir('/docs');
// Log each item in the list
for (var i = 0; i < dirList.length; i++) {
Log(dirList[i].Name);
}
// ...
}
Example (with mask parameter)
ts
{
// ...
// Acquire directory list
var dirList = cli.ListDir('/docs', '*.docx'); // only list *.docx files
// Log each item in the list
for (var i = 0; i < dirList.length; i++) {
Log(dirList[i].Name);
}
// ...
}