function ListFiles(directory, mask)


The ListFiles method retrieves the list of files (not sub-directories) contained inside the specified directory.
The result of this function is returned as a JavaScript array of objects. Each object is of DirListItem type.

Once a resulting array has been obtained, you can use the typical JavaScript ways to iterate over it, and check the various property of each one of its items.


The directory parameter must specify an existing directory.
The mask parameter must specify to file-mask to match while searching, wildcards are supported (for example: *.docx).


This function is NOT recursive, so only files that are contained inside directory will be returned. Files contained in sub-directories of directory will not be included in the results. For a recursive version of this function, please, look at ListFilesR.


Example 1 (one way to iterate over a directory list, using a for cycle):

{
 var scli = new SftpClient();
 scli.Host = 'your.sftpserver.com:22';
 scli.User = 'someusername';
 scli.KeyFile = './my_id.rsa';
 if (scli.Connect()) {
  dirList = scli.ListFiles('/docs', '*.docx');
  for (var i = 0; i < dirList.length; i++) {
   Log(dirList[i].Name);
  }
  scli.Close();
 }
 scli = null
}


Example 2 (a different way to iterate over a directory list, using forEach):

{
 var scli = new SftpClient();
 scli.Host = 'your.sftpserver.com:22';
 scli.User = 'someusername';
 scli.KeyFile = './my_id.rsa';
 if (scli.Connect()) {
  dirList = scli.ListFiles('/docs', '*.xlsx');
  dirList.forEach(myFunction);
  function myFunction(item, index, array) {
    Log(item.Name + ' [' + item.Size + ' bytes] [' + item.Type + ']');
  }
  scli.Close();
 }
 scli = null
}