function SortDir(dirList, sortBy, direction);

This function sorts (re-orders) a directory list previously retrieved by either one of the following client object methods (regardless of which client object has generated the list): ListDir, ListDirR, ListFiles, ListFilesR.

Here's an explanation of the parameters this function takes:

  • dirList is a JavaScript array in which each item is of DirListItem type, typically this list is the result of a call to a client method that retrieves a directory/file list, as explained here above
  • sortBy is a string parameter and can be either one of the following:
    • "name" sorts the list by file name
    • "size" sorts the list by file size
    • "time" sorts the list by the timestamp of each file
  • direction is an optional parameter; it can be either Ascending or Descending. If this parameter is not specified, Ascending will be assumed by default.


 var scli = new SftpClient();
 scli.Host = '';
 scli.User = 'someusername';
 scli.KeyFile = './my_id.rsa';
 if (scli.Connect()) {
  dirList = scli.ListDir('/docs', All);
  SortDir(dirList, "time", Descending); // sorts from newest to oldest item
 scli = null