files([folder], [settings])

Gets all files of a folder and returns them in an array of file objects. The settings object can be used to restrict the search to certain file types only, to include hidden files and to include files in subfolders.

Type: function

Parameter(s):

  • folder {} Optional:

    The folder that holds the files or a string describing the path to that folder.

  • settings {Object} Optional:

    A settings object to control the function’s behavior.

  • settings.filter {} Optional:

    Suffix(es) of file types to include. Default: "*" (include all file types)

  • settings.hidden {Boolean} Optional:

    Hidden files will be included. Default: false

  • settings.recursive {Boolean} Optional:

    Searches subfolders recursively for matching files. Default: false

Returns:

  • {Array}:

    Array of the resulting file(s). If no files are found, an empty array will be returned.

Example(s):

Get a folder from the desktop and load all its JPEG files

var myImageFolder = folder("~/Desktop/myImages/");
var myImageFiles = files(myImageFolder, {filter: ["jpeg", "jpg"]});

If the document is saved, load all files from its data folder, including from its subfolders

var myDataFolder = folder();
var allMyDataFiles = files(myDataFolder, {recursive: true});