DriveApp.getFolders() not working as expected

Solution 1:

Get All My Files

function getAllMyFiles(folder=DriveApp.getRootFolder()) {
  const ss = SpreadsheetApp.getActive();
  const sh = ss.getSheetByName('Sheet0');
  let files = folder.getFiles();
  while(files.hasNext()) {
    let file = files.next()
    sh.appendRow([file.getName(),file.getId()]);
  }
  let sfldrs = folder.getFolders();
  while(sfldrs.hasNext()) {
    let sfldr = sfldrs.next();
    getAllMyFiles(sfldr)
  }
}