user925738
user925738

Reputation: 45

migrate from DocsList to DriveApp

I'm new to google scripts and was able to manipulate some code to work for a project, but it will no longer work as a result of the following:

ReferenceError: "DocsList" is not defined.Dismiss

Here is the code I have:

function report() {
  var folder = DocsList.getFolder("FOLDER NAME HERE");
  var contents = folder.getFiles();
  var file;
  var data;

  var sheet = SpreadsheetApp.getActiveSheet();
  sheet.clearContents();
  sheet.appendRow(["URL", "Employer"]);
  for (var i = 0; i < contents.length; i++) {
    file = contents[i];
    var qaDate,qaERName
    if (file.getFileType()==DocsList.FileType.SPREADSHEET) {
      var dataSheet = SpreadsheetApp.open(file).getSheetByName("data");
      var configSheet = SpreadsheetApp.open(file).getSheetByName("Config");

I have a few references to DocsList, I've done some digging and cant figure out how to get something similar to getfolder

Upvotes: 0

Views: 922

Answers (1)

Alan Wells
Alan Wells

Reputation: 31310

Let's start with the first line:

var folder = DocsList.getFolder("FOLDER NAME HERE");

If you go to the documentation, and look at all the methods for DriveApp that have anything to do with folders, you'll see four methods:

  • getFolderById(id)
  • getFolders()
  • getFoldersByName(name)
  • getRootFolder()

There is only one method that will get just one folder, getFolderById(id). If you are getting the same folder every time, and you can easily get the ID, then use that option. If that is not possible, then you can use getFoldersByName(name), but that gets multiple folders. Even though it gets multiple folders, you can easily get just the first folder.

var folders = DriveApp.getFoldersByName('Folder Name');
var folder = folders.next();

Logger.log('folder: ' + folder.getName());

So, start there, and make that change.

Upvotes: 2

Related Questions