How can i list all sub folders name from google drive into google sheets?
Here is the code, it's working but I cant put them in to google sheets.
enter image description here In the place of logger i need replace the google sheet. Please help me out in this scenario?
If you are planning to use custom function to write the list of sub-folder names in Google Sheets, It will not work because your function require authorization when using DriveApp it will throw an error message
You do not have permission to call X service.
, the service requires user authorization and thus cannot be used in a custom function as stated here.You can write your sub-folder names in Google Sheets using Spreadsheet Service. But you need to specify the specific sheet and the cell where you want to write your data.
Sample Code:
What it does?
childNames
array using Array.prototype.push()childNames
array to the active sheet starting from the active cell. Using Sheet.getRange(row, column, numRows, numColumns) and Range.setValues(values)Output:
If you want to write the sub-folder names on a single cell(in your active cell), you can replace
activeSheet.getRange(activeCell.getRow(),activeCell.getColumn(),childNames.length,1).setValues(childNames);
to
activeCell.setValue(childNames.flat().toString());
Output: