Skip to content

Instantly share code, notes, and snippets.

@woodwardtw
Last active June 8, 2022 14:52
Show Gist options
  • Save woodwardtw/0aa352d43e135baf76de to your computer and use it in GitHub Desktop.
Save woodwardtw/0aa352d43e135baf76de to your computer and use it in GitHub Desktop.
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
Copy link

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