I am trying to write a simple Google Apps Script to list the files in a Google Team Drive and I am not having much success.
Here is the code:
function start()
{
Logger.log("Starting application...");
var startingFolders = DriveApp.getFoldersByName("Temp");
if (startingFolders.hasNext())
{
// Assuming only one folder with that name
accessFiles(startingFolders.next());
}
else
Logger.log("Folder not found");
}
function accessFiles(folder)
{
Logger.log("Folder: %s", folder.getName());
// Print some file properties
var files = folder.getFiles();
while (files.hasNext())
{
var file = files.next();
Logger.log("Working on file %s. Current access: %s.", file.getName(), file.getSharingAccess());
// some work here...
}
// Explore subfolders
while (folder.hasNext())
{
var subfolder = folder.next();
accessFiles(subfolder);
}
}
The problem is that the log always prints the "Folder not found" message. "Temp" is a folder in a Team Drive that I have Full access to. Note that I am trying to use the Google Apps Script and not the REST API.
I am not sure what I am doing wrong, or if Team Drives are not supported yet...
Any help would be appreciated! Thanks.