Estoy tratando de importar el nombre y la URL de la subcarpeta (no archivos) que se encuentra en la carpeta principal a Hojas de cálculo de Google
Intenté trabajar en este código pero no me ayudó a lograr mi tarea.
var SS = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet3"); function getFolderArray(folderId){ var folder = DriveApp.getFolderById(folderId); var Folders = folder.getFolders(); var FolderList = []; //Loop though Folders and add names and urls to the array while (folder.hasNext()){ var Folder = Folders.next(); var FolderName = Folder.getName(); var FolderUrl = Folder.getUrl(); FolderList = FolderList.concat([[FolderName, FolderUrl]]); } //See returned FolderList in a log //Logger.log( FolderList ) //Preview Returned Array return FolderList } //Prints any 2D array to a range that starts with the selected cell function printArrayToSelection(twoDimArr){ var firstCell = SS.getActiveCell(); var lastCell = firstCell.offset(twoDimArr.length - 1, twoDimArr[0].length - 1); var destinationRange = SS.getActiveSheet().getRange( firstCell.getA1Notation() + ':' + lastCell.getA1Notation()); destinationRange.setValues(twoDimArr); } //Print the actual data function printFolderArray(){ printArrayToSelection(getFolderArray('0B4-wws2P3gUhcExqWEI0VTlrNm8')); }¿Puedo saber qué salió mal?
Probar
function listOfFoldersByID() { var folderid = '_______your folder ID___________'; // change FolderID SpreadsheetApp.getActiveSheet().clear(); SpreadsheetApp.getActiveSheet().appendRow(["parent","folder","URL"]); try { var parentFolder =DriveApp.getFolderById(folderid); listSubFolders(parentFolder,parentFolder.getName()); } catch (e) { Logger.log(e.toString()); } } function listSubFolders(parentFolder,parent) { var childFolders = parentFolder.getFolders(); while (childFolders.hasNext()) { var childFolder = childFolders.next(); SpreadsheetApp.getActiveSheet().appendRow([parent,childFolder.getName(),childFolder.getUrl()]); listSubFolders(childFolder,parent + "|" + childFolder.getName()); } }