Miscellaneous Functions

Array of folders in a directory

function getFoldersInDirectory(directoryPath)
{
    var varDirs = new Array();
    var varDirectory = new File(directoryPath);
    var varFiles = varDirectory.listFiles();

    for (var ff = 0; ff < varFiles.length; ff++)
    {
        if (varFiles[ff].isDirectory())
        {
            varDirs.push(varFiles[ff]);
        }
    }

    return varDirs;

}

Array of files in a directory

function getFilesInDirectory(directoryPath)
{
    var varDirs = new Array();
    var varDirectory = new File(directoryPath);
    var varFiles = varDirectory.listFiles();

    for (var ff = 0; ff < varFiles.length; ff++)
    {
        if (varFiles[ff].isFile())
        {
            varDirs.push(varFiles[ff]);
        }
    }

    return varDirs;

}

Check if a file exists in a directory

function isFileInDirectory(file, directoryPath)
{
    var varFile = new File(directoryPath + file);
    return varFile.exists();
}