Google Apps Script for Google Drive Search

Can I use Google Apps Script to search Google Drive for documents and folders?

Google killed its own document / drive gadget because it relies on iGoogle and Google Enterprise support.

thanks

+4
source share
2 answers

I think you are looking for SearchFile and SearchFolder from DriveApp. A complete list of options is available in the Google Drive SDK documentation.

I ran several tests and it seemed that I could not do 1 search and get the files and folders to call the search function from the Google Drive API.

, , 2013

function myFunction() {
  var searchFor ='title contains "2013"';
  var names =[];
  var files = DriveApp.searchFiles(searchFor);
  while (files.hasNext()) {
    var file = files.next();
    names.push(file.getName());
  }
  var folders = DriveApp.searchFolders(searchFor);
  while (folders.hasNext()) {
    var file = folders.next();
    names.push(file.getName());
  }
  for (var i=0;i<names.length;i++){
    Logger.log(names[i]);
  }

}
+4

function searchDrive() {
  var folderToSearch = "FolderName";
  var folders = DriveApp.getFoldersByName(folderToSearch);
  Logger.log(folders);

  var fileToSearch = "fileName";
  var files = DriveApp.getFilesByName(fileToSearch);
  Logger.log(files);
}

.

+2

All Articles