I have a gscript that will return all the files in a folder adn write to the open spreadsheet. I would like to add the files in all the subfolders as well but can't quite make it work. Here is the script for the files in the folder with the contents of the subfolders:
function getFiles() {
// Get the active spreadsheet file and the active sheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
var ssid = ss.getId();
// Look in the current folder e.g. if this spreadsheet is in 'My Folder'
// this routine will return all of the files in 'My Folder'.
var ssparents = DriveApp.getFileById(ssid).getParents();
var sheet = ss.getActiveSheet();
// Clear the area, add the headers ready for results
var headers = [["Full Folder Ref", "File Name", "Last Updated", "File Owner", "File URL", "In Folder"]];
sheet.getRange("A1:F").clear();
sheet.getRange("A1:F1").setValues(headers);
// Loop through all the files, add the values to the spreadsheet.
var folder = ssparents.next();
var files = folder.getFiles();
var i=1;
while(files.hasNext()) {
var file = files.next();
// get the full folder ref
var fileParents = file.getParents()
folders = [];
while (fileParents.hasNext()) {
fileParents = fileParents.next();
folders.push(fileParents.getName());
fileParents = fileParents.getParents();
}
// create the row
if(ss.getId() == file.getId()){
continue;
}
sheet.getRange(i+1, 1, 1, 6).setValues([[folders.reverse().join("/") , file.getName(), file.getLastUpdated(),file.getOwner().getName(), file.getUrl(), folder.getName() ]]);
i++;
}
}
Can someone help me add the subfolder files please.
thank you