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

227
Views
How to Import Google Drive Sub-Folder URL to Google Sheet

I'm trying to import the Sub-folder's (Not Files) Name & URL which is in the Main Folder to Google Sheets

enter image description here

I tried working on this code but it didn't help me to achieve my task.

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'));
    }

Can I know what went wrong?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Try

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());
  }
}
about 4 years ago · Juan Pablo Isaza Report
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!