I am trying to be a little organized, and want a way to get a list of all folders in my Google Drive in Google Sheet.
It should not have the Files, only folders.
I was able to find following code, but it lists file name too, I only want folders. And also a way to specify how deep in hierarchy should it go, like 2 levels or 3 levels etc.
// replace your-folder below with the folder for which you want a listing
function listFolderContents() {
var foldername = 'your-folder';
var folderlisting = 'listing of folder ' + foldername;
var folders = DriveApp.getFoldersByName(foldername)
var folder = folders.next();
var contents = folder.getFiles();
var ss = SpreadsheetApp.create(folderlisting);
var sheet = ss.getActiveSheet();
sheet.appendRow( ['name', 'link'] );
var file;
var name;
var link;
var row;
while(contents.hasNext()) {
file = contents.next();
name = file.getName();
link = file.getUrl();
sheet.appendRow( [name, link] );
}
};