Permissions DriveApp.getFolderById

I am trying to "upgrade" an old script from DocsList to DriveApp and have a problem calling getFolderById . The script worked using DocsList.getFolder . I have a (previously created) folder called "Email Archive" that I am trying to access in a script. Through the use of logs and a execution script, I verified that I am correctly passing the string "Email Archive" in the baseFolder parameter to the following statement:

var baseFolderObject = DriveApp.getFolderById (baseFolder);

When this statement is executed, I get the following error:

The execution failed: no elements with the specified identifier can be found, or you do not have access to it.

The Email Archive folder was created earlier by the same script with the script call docsList.CreateFolder , and there were no permissions.

Do I need to do something to change the permissions of the folder to allow my script to access it now when I use DriveApp instead of DocsList ? Do I need to create a new folder using DriveApp and specify permissions, and if so, what permissions did I set to allow my script to access the folder and create subfolders and files, not allowing it to be visible to the entire Internet?

Thanks in advance for your help,

~ Jim Fennell

0
source share
2 answers

In DriveApp, you can get a folder by ID or by name. You pass the name to the getFolderById () method. Try the following:

var myFile = DriveApp.getFilesByName(baseFolder).next(); 

getFoldersByName returns an iterator that has the standard syntax hasNext () / next () that executes the iterator. The above code saves the first folder returned with the name specified in 'baseFolder' to the variable myFile. Remember that in the driver several folders can have the same name, therefore, return the iterator to the same folder.

+1
source

var myFolder = DriveApp.getFoldersByName ("Email Archive"). next ();

-1
source

Source: https://habr.com/ru/post/1241568/


All Articles