Syncplify.me AFT! Manual

Contents:

  • Introduction
  • Getting started
    • Getting help
    • How to run your own aftJS scripts
      • Run scripts from within the web interface
      • Run scripts via REST API
      • Run scripts interactively from the command prompt
      • Run scripts interactively by double-clicking on them
      • Run scripts from the command-line (but via REST API)
    • Environment variables
    • The aftJS language
    • System requirements
  • aftJS language documentation
    • aftJS-specific types
      • Options (for ALL client objects)
      • Directory list item
    • Client objects and functions
      • AWS S3 client object
      • Azure Blob Storage client object
      • Google Cloud Storage client object
      • SFTP client object
      • FTP(E/S) client object
      • Client-object common methods
        • Connect
        • Close (disconnect)
        • ListDir (listing a directory)
        • ListDirR (recursive directory list)
        • ListFiles (search for files)
        • ListFilesR (recursive file search)
        • Stat (get object metadata)
        • MakeDir (create a directory)
        • RenDir (rename a directory)
        • DelDir (delete a directory)
        • DelTree (delete a directory tree)
        • Delete (delete a file)
        • Rename (rename/move a file)
        • Upload (upload files)
        • UploadR (recursive file upload)
        • UploadWithPath (skip paths)
        • UploadWithPathR (recursive + skip paths)
        • Download (download files)
        • DownloadR (recursive file download)
        • DownloadWithPath (skip paths)
        • DownloadWithPathR (recursive + skip paths)
      • Protocol-specific methods
        • SetMode (FtpsClient object)
    • Remote file-system watcher
      • RemoteWatcher object
      • WatchDir (watch a directory)
      • Events (to watch for)
      • Delay notifications
      • Inclusion/Exclusion filters
      • Start (begin watching)
      • Events (polling for)
    • Local file-system watcher
      • FsWatcher object
      • WatchDir (watch a directory)
      • Events (to watch for)
      • Delay notifications
      • Inclusion/Exclusion filters
      • Start (begin watching)
      • Events (polling for)
    • Local file-system functions
      • ListDir (list local directory)
      • ListDirR (recursive directory list)
      • CopyFile (copy local file)
      • MoveFile (move/rename local file)
      • DelFile (delete local file)
      • SecureErase (securely delete file)
      • MakeDir (create local directory)
      • DelDir (delete local directory)
      • DelTree (delete local dir tree)
      • ReadTextFile (read a text file)
      • Write text to file (2 ways)
      • Zip (create a zip archive)
      • FileType (identify file MIME-type)
    • Web (HTTP/HTTPS) functions
      • HttpCli configuration methods
      • HttpCli http/https verbs
      • HttpRes response object
    • AMQP message queue functions
      • AMQP client object properties
      • Connecting to an AMQP queue
      • Monitoring a queue
      • Processing incoming messages
    • Cloud and integration functions
      • Send to Slack (webhook)
      • Send SMS via Twilio
    • Email and communication functions
      • SendMailViaSMTP function
    • Process management
      • Run (execute a process)
      • RunAsync (async run a process)
    • Image processing functions
      • JPEGResample (resize a JPEG)
      • PNGResample (resize a PNG)
      • JPEGMetadata (extract EXIF)
      • PNGMetadata (extract PNG info)
    • Additional security functions
      • GeneratePGPKeys function
      • PGPEncryptFile function
      • PGPDecryptFile function
    • Miscellaneous functions
      • GetSecret function
      • Log (custom log line)
      • Detecting halt requests
      • Sleep (pause execution)
      • Extract file path
      • Extract file name
      • Extract file extension
      • Num-to-string (padded)
      • Unique IDs (UUID)
    • More (cool) stuff we put in aftJS
      • How to “require” a Node.js module
      • The famous “underscore.js” library
Syncplify.me AFT! Manual
  • »
  • aftJS language documentation »
  • Client objects and functions »
  • Client-object common methods »
  • ListFilesR (recursive file search)

ListFilesR (recursive file search)¶

function ListFilesR(directory, mask: string) []DirListItem

The ListFilesR method retrieves the list of files (only files, not sub-directories) found inside the specified directory and all of its sub-directories (this function is recursive).

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 on the remote side.

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

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

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

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

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

© Copyright 2021, Syncplify, Inc..