0
votes

In Google Drive, I'm searching for a specific file that contain words "Verification Visit" and "completed" where the file type need to be a spreadsheet(.xlsx) type file. The searching will go through a parent folder and then into sub folders. So the particular files will be stored in some of the sub folders (Google Drive -> Parent folder -> Sub folders).

Here is the code:

function getChildFolders(parentName, parent, sheet, voidFolder, excluded) {

var childFolders = parent.getFolders();  
 
var folder = childFolders.next();

var failIter = folder.searchFiles('title contains "completed"');

  while (failIter.hasNext()) {     
    var fail = failIter.next();
    var failWithTitle = fail.getName();


var files = folder.getFilesByType(MimeType.MICROSOFT_EXCEL);

var output = [];
var path;
var Url;
var fileID;

while (files.hasNext()) {    
  var childFile = files.next();
  var fileName = childFile.getName();
  

  path = parentName + " |--> " + fileName ;
 
  fileID = childFile.getId();
  Url = "https://drive.google.com/open?id=" + fileID;
  
  output.push([fileID, fileName, path, Url]);
}
if (output.length) {
  var last_row = sheet.getLastRow();
  sheet.getRange(last_row + 1, 1, output.length, 4).setValues(output);
}

getChildFolders(parentName + " |--> " + fileName, folder, sheet, voidFolder, excluded);
}
}

I have successfully implemented the two conditions (file that contains specific name and also the file type) in this function. The problem here is the searching process of the file in the sub folder only does on the first sub folder and it doesn't proceed searching into the next sub folder. It only list the files from the first sub folder but not from the other sub folders.

I am getting an error message telling "Exception: Cannot retrieve the next object: iterator has reached the end."