magichand
magichand

Reputation: 23

Script for Search in Google Drive

I have a script that should search all the files in Google drive. I implemented the script into one of Google sites page. The script works only for the files that are in root folder but doesn't work for the files that are in sub-folders. Any help appreciated. Thank you

Here is the current script:

function doGet(e) {
  var results = DriveApp.getFolderById('yourGoogleDriveId').searchFiles('fullText contains "' + e.parameter.q + '"');
  var output = HtmlService.createHtmlOutput('Results: <br /><br /><ul>');
  while (results.hasNext()) {
    var file = results.next();
    output.append('<li><a href="' + file.getUrl() + '">' + file.getName() + '</a></li>');
  }
  output.append('</ul>');
  return output;
}

Upvotes: 1

Views: 1552

Answers (1)

Sangbok  Lee
Sangbok Lee

Reputation: 2229

As @Cesar mentioned, DriveApp.getFolderById().searchFiles() should be DriveApp.searchFiles(). Two class DriveApp and Folder both have searchFiles() method, but only the former searches recursively. Read the documentations.

I copied your code and tested it (with modifedDate to speed up) and it went fine.

Upvotes: 2

Related Questions