File List

Files

The main data source of magnetron are the files that are dropped by the user on the app. You can access this file list from within a recipe with the function getFiles() and you may modify the file properties with the following functions;

File Properties

Each File can have a set of Properties for file specific data. You can access this these properties with getFileProperty(), set them with setFileProperty() or remove them using removeFileProperty().

You can also add or remove files and its properties by calling setFiles(). But note that this will remove and completely replace the file list with the given file data. This function will process the given file data as a batch of multiple setFileProperty() calls, you should only use it when explicily needed and where a simple call to setFileProperty() won't suffice. Calling setFiles() in fast succession with a lot of files and properties can cause it to fail to process.

File Properties shortcuts

Some of the properties can be set with convenience functions below. These are simply shortcuts that interact with the user experience for files in the list.

file_tooltip
getFileTooltip, setFileTooltip, removeFileTooltip

file_status
getFileStatus, setFileStatus, removeFileStatus

file_icon
getFileIcon, setFileIcon, removeFileIcon

file_icon_color
getFileIconColor, setFileIconColor, removeFileIconColor

getFileIcon
get the current icon selection of a file in the list
getFileIconColor
get the current icon color of a file in the list
getFileProperty
gets a property of the file list from the magnetron app user interface
getFiles
returns an array of all files added to the users file list
getFileStatus
gets the file status property of a file in the list
getFileTooltip
gets the file tooltip property of a file in the list
removeFileIcon
removes the icon property of the file list from the magnetron app user interface
removeFileIconColor
removes the icon color property of the file list from the magnetron app user interface
removeFileProperty
removes a property of the file list from the magnetron app user interface
removeFileStatus
removes the file status property of the file list from the magnetron app user interface
removeFileTooltip
removes a file tooltip property of the file list from the magnetron app user interface
setFileIcon
set the icon property of the file list from the magnetron app user interface
setFileIconColor
set the icon color property of the file list from the magnetron app user interface
setFileProperty
sets a property of the file list from the magnetron app user interface
setFiles
(re)sets the complete file list with a new array
setFileStatus
set a file status property in the file list from the magnetron app user interface
setFileTooltip
set a file tooltip property in the file list from the magnetron app user interface

examples

function TestFiles()
{
    var files = getFiles();

    for (i=0;i<files.length;i++)
    { 
        // add file properties to the files in the file list
        var info = getPathInfo(files[i]["path"]);
        files[i] = mergeObject(info, files[i]);

        files[i]["bytes"] = getFileBytes(files[i]);

        // add and remove test
        files[i]["test"] = files[i]["ext"];
        files[i] = removeProperty(files[i], "test");

        // alternative
        setFileProperty(files[i].path, "key", "test_value");
        echo("key: " + getFileProperty(files[i].path, "key"));
        removeFileProperty(files[i].path, "key");
    }
    
    setFiles(files); // update the file list

    echo("updated_files\n" + objectToString(getFiles()));
}

// change the icons and status of the files in the app file list with shortcuts
function TestFileFeedback()
{
    var files = getFiles();

    for (i=0; i<files.length; i++)
    { // add file properties
        setFileTooltip(files[i].path, files[i].index, "testing the tooltip\nspace for more details and feedback");
        setFileIcon(files[i].path, files[i].index, "CheckCircleO");
        setFileIconColor(files[i].path, files[i].index, "FF3aac4d");
        setFileStatus(files[i].path, files[i].index, "success");
    }
}

// change the group property of the files in the app file list
function TestFileGroups()
{
    var files = getFiles();

    for (i=0; i<files.length; i++)
        setFileProperty(files[i].path, "group", i + 1); // add a group file property
}