I'm trying to copy to steps in https://ctrlq.org/code/19854-list-files-in-google-drive-folder
It successfully made the headers for the columns in the sheet, but it didn't get/print any data in the rows. Where did I go wrong?
This is what I have:
/* Code written by @hubgit
https://gist.github.com/hubgit/3755293
Updated since DocsList is deprecated
*/
function listFilesInFolder(folderName) {
var folder = DriveApp.getFoldersByName(folderName).next();
var contents = folder.getFiles();
var file, data, sheet = SpreadsheetApp.getActiveSheet();
sheet.clear();
sheet.appendRow(["Name", "Date", "Size", "URL", "Download", "Description", "Type"]);
for (var i = 0; i < contents.length; i++) {
file = contents[i];
if (file.getFileType() == "SPREADSHEET") {
continue;
}
data = [
file.getName(),
file.getDateCreated(),
file.getSize(),
file.getUrl(),
"https://docs.google.com/uc?export=download&confirm=no_antivirus&id=" + file.getId(),
file.getDescription(),
file.getFileType().toString()
];
sheet.appendRow(data);
}
};
folderName
being received by thelistFilesInFolder
function? Add this line of code at the very top of the function:Logger.log('folderName: ' + folderName);
. Run the code, then in the VIEW menu, choose LOGS. Is the correct folder name printed in the Log? – Alan Wellsvar folder = DriveApp.getFoldersByName(folderName).next();
Removenext()
from the end, so that you just have:var folder = DriveApp.getFoldersByName(folderName);
Then addLogger.log('folder: ' + folder);
after the modified line. Check the Logs. It should show a folder iterator or an object. If there are no folders with that name found, thennext()
won't work. There is no "next" folder. – Alan Wellsfolder
: Add a line:var folder = "my Folder Name Here";
You can also run the debugger. Choose the name of the function that is in the drop down list to the right of the bug icon, click on line number 10 so that a red dot shows up on the line number on the left. Then click the icon of the bug. All the variable values with their values will appear at the bottom of the window. You can then execute each line one at a time by clicking the icon just to the right of the big square. – Alan Wells