Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

190
Views
How can I pass a stored value from one "while" another "while"?

In Google Sheet, I have already list out all the filtered files as needed throughout the parent folder and child folder. I have pushed all the important details into the sheet as well.

My issue now is I am trying to get each childFolderId value from childFolders while and pass it into the fileIter while and then push into a list of array to be displayed in Google Sheet.

Here is the codes:

var parent = DriveApp.getFolderById(folderId);                          
                
getChildFiles(parentName, parent, currentSheet, list, excluded);

The main function is:

function getChildFiles(parentName, parent, sheet) {

var fileIter = parent.searchFiles("title contains 'completed'and title contains 'Verification 
Visit Direct Suppliers'and mimeType='application/vnd.openxmlformats- 
officedocument.spreadsheetml.sheet'"); 

var output = [];

var childFolders = parent.getFolders();

while (childFolders.hasNext()) {
  var childFolder = childFolders.next();
  var childFolderName = childFolder.getName();

getChildFiles(
  parentName + ' |--> ' + childFolderName, childFolder,sheet
  );   

 } 

while (fileIter.hasNext()) { 
 var file = fileIter.next();
 var fileName = file.getName();
 var fileID = file.getId();

 var path = parentName + ' |--> ' + fileName;

 output.push([fileID, fileName, path]);
}

 if (output.length) {
 var last_row = sheet.getLastRow();
 sheet.getRange(last_row + 1, 1, output.length, 3).setValues(output);
 SpreadsheetApp.flush();
} 

}

I am trying to get the childFolderId without messing up the filtering code. This is because if i insert the fileIter while inside the childFolders while, None of the files is listed in the google sheet.

But if i split both while i manage to list all the files i need except the childFolderId

How can I get the value of childFolderId and push it into the sheet?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!