Create a gist now

Instantly share code, notes, and snippets.

List all files in a folder (Google Apps Script)
function listFilesInFolder() {
var folder = DocsList.getFolder("Maudesley Debates");
var contents = folder.getFiles();
var file;
var data;
var sheet = SpreadsheetApp.getActiveSheet();
sheet.appendRow(["Name", "Date", "Size", "URL", "Download", "Description", "Type"]);
for (var i = 0; i < contents.length; i++) {
file = contents[i];
if (file.getFileType() == "SPREADSHEET") {
data = [
"" + file.getId(),
mike018 commented May 20, 2014

Hi Hubgit,

Is there a way also to get all files inside a sub folder? let's say in the above code, "Maudesley Debates" is the main folder then assuming that there is a sub folder named "Sub1" and "Sub2"
Sub1 and Sub2 has 3 files each inside.

so how to I append that in the spreadsheet as well..

further, is there a way that folder will be list down in a new column like

File Name | Folder Name
testfile I Maudesley Debates
testfile2 | Maudesley Debates,Sub1
testfile3 | Maudesley Debates,Sub1
testfile4 | Maudesley Debates,Sub2

so basically I want to list down all the folder the file is connected into and separate it with comma.

Hope to hear something from you the soonest as I'm really stuck with this challenge and i'm really hoping that you could help me out.

Please advise..
Thanks in advance!


@mike018 You found the answer to your question? Im also facing the same issue :-(

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