uvi-script
Musical event scripting with Lua
AsyncListFilesTask Class Reference

An Asynchronous task that lists the files of a folder. More...

Inheritance diagram for AsyncListFilesTask:
AsyncTask

Public Attributes

table result
 array of entries, empty when the folder could not be listed.
 
string error
 why the folder could not be listed ("folder not found: ..."), nil on success.
 
- Public Attributes inherited from AsyncTask
int id
 unique identifier for this task
 
bool finished
 a flag to indicate whether the task has been completed. Also true after the task was cancelled: check success or state.
 
float progress
 a value between 0 and 1 to be notified of the task's progress.
 
bool success
 a flag to indicate whether the task has been successful.
 
string state
 a string to indicate the current task state (pending | running | finished | cancelled)
 

Additional Inherited Members

- Public Member Functions inherited from AsyncTask
void cancel ()
 notify the task that it should be cancelled.
 

Detailed Description

An Asynchronous task that lists the files of a folder.

Tasks returned by listFiles().

Each entry of result is a table:

  • path: absolute path of the file or folder
  • name: file name, extension included
  • isDirectory: true for a folder (folders are listed only when the patterns are "")
  • size: size in bytes, 0 for a folder
  • modified: last modification time, in seconds since 1970-01-01 UTC (0 inside a sound bank)

Entries are sorted by path, byte order: "B.json" comes before "a.json".

Example:

listFiles(getUserLocation("My Instrument").."/Presets", "*.json", false, function(task)
if task.error then print(task.error) return end
for _, entry in ipairs(task.result) do print(entry.name) end
end)
function listFiles(path, patterns, recursive, callback)
list the files of a folder.
Definition api.lua:316
string getUserLocation(string productName, string vendorName)
Per-product user folder, Documents/[vendorName]/[productName], for a sound bank to keep its user pres...

See the UserPresetBrowser example for a complete user preset manager (listFiles, saveData, loadData and browseForFile).

Member Data Documentation

◆ result

table AsyncListFilesTask::result

array of entries, empty when the folder could not be listed.

Each read builds a new table: keep it in a local rather than reading it in a loop.