google-apps-scriptsearchgoogle-drive-apigetfiles

Google-App-Scripts-Search files does not find spreadsheet


I created 3 untitled Google Spreadsheets to test this script. Search in My Drive for title:untitled or just untitled found all three, but in this script searchFiles method finds the Doc and the Slide but not the Spreadsheet and getFilesByName does not find any! I also tried "untitled" with the getFilesByName and still found none. Any ideas what is wrong?

function findUntitledFiles() {
  Logger.log("Begin findUntitledFiles()");
  var fileName = "*untitled*";
  var file, folder , filesIt , foldersIt;
  filesIt = DriveApp.searchFiles(' title contains "untitled" ') ;  // did not find spreadsheet
//  filesIt = DriveApp.getFilesByName(fileName) ;   // found none
  while (filesIt.hasNext() )  {
    file = filesIt.next() ;
    Logger.log("file.getName() = " + file.getName() );
    foldersIt = file.getParents() ;
    folderName = (foldersIt.hasNext()) ? foldersIt.next().getName() : "unknown" ;
    Logger.log( "folder  " + folderName + "    file name: " + file.getName() );
  } 
}

Solution

  • I created a new spreadsheet for which I was the owner and now it is found by the script.