Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
google script to list all subfolder content of a particular folder
function listFolders(folder) {
var sheet = SpreadsheetApp.getActiveSheet();
sheet.appendRow(["Name", "Folder", "Date", "Size", "URL", "Download", "Description", "Type"]);
var folder = DriveApp.getFolderById("0BxGcFSIReuGfOTJ0dTloY2xWS0E");
var subfolders = folder.getFolders();
while (subfolders.hasNext()) {
//Logger.log(folder);
var name = subfolders.next();
while (subfolders.hasNext()) {
//Logger.log(folder);
var name = subfolders.next();
var files = name.getFiles();
var cnt = 0;
var file;
while (files.hasNext()) {
var file = files.next();
cnt++;
Logger.log(file);
Logger.log(cnt);
data = [
file.getName(),
name, //folder name
file.getDateCreated(),
file.getSize(),
file.getUrl(),
"https://docs.google.com/uc?export=download&confirm=no_antivirus&id=" + file.getId(),
file.getDescription(),
file.getMimeType(),
];
sheet.appendRow(data);
};
}
}
}
@dcuellar

This comment has been minimized.

Copy link

@dcuellar dcuellar commented Feb 21, 2019

This is similar to what I was looking for. How can this be enhanced to continue looking into those sub-folder's sub-folders and so on?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment