How to update DocsList to DriveApp in my code

Many of the DriveApp methods are identical to DocsList. So, in many cases, you can simply replace DocsList with DriveApp.

Problems arise with the old getFolder() method.

var folder = DocsList.getFolder('Name of your folder');

In this case, simply replacing DocsList with DriveApp will give you a problem. There is no getFolder() method for DriveApp. In Google Drive, you can have multiple files and folders with identical names (But different ID’s). The old DocsList, getFolder() method did not take this situation into account. With DriveApp, you can still search for a folder by name, but the return is a Folder Iterator. With DriveApp the method name for getting a folder by name is very slightly different; it’s “folders”, with an “s” on the end. getFoldersByName(name) Plural, not singular. So, even though 98% of the time, getting folders by name will result in only one folder, you still need process the Folder Iterator. You don’t need to loop through the folder iterator. You can just get the first folder. Just use the next() method without using a programming loop.

Folder Iterator

So, I suggest that you do just replace DocsList with DriveApp except in the case of getting a folder by name. Read the documentation, and fix that line of code, then run it. If you get an error, VIEW the EXECUTION TRANSCRIPT, and it will probably tell you what line of code failed. If you still need help, always post what line of code failed.

Also, there is no addToFolder() method of the new DriveApp Folder class.

Folder Class

You will need to change that to:

folder.addFile(moveFile);

addFile() Method

Leave a Comment