0

I'd like to have the script coding itself change as I change the data in a sheet. For example, I have a script set to list the all the files in a particular folder as well as their ids. It spits them out starting in A1 of Sheet1. I'd like FolderId to by dynamic though, so that if in Sheet1!H1 for example, I have a different FolderId pasted, the script below will update based on that, which would allow me to add a menu button running the script, as opposed to updating the script with the new FolderId each time I want to run this for a different folder. Is this possible, or am I looking at it from the wrong angle?

function list_all_files_inside_one_folder_without_subfolders(){ 
  var sh = SpreadsheetApp.getActiveSheet(); 
  var folder = DriveApp.getFolderById('1eG0gQ97a_Qj8mcQ50gaVYShPxx-YEDY8'); 
  var list = []; list.push(['Name','ID','Size']); 
  var files = folder.getFiles(); 
  while (files.hasNext()){ 
    file = files.next(); 
    var row = []
      row.push(file.getName(),file.getId(),file.getSize()) list.push(row); 
  }
  sh.getRange(1,1,list.length,list[0].length).setValues(list); 
}
  • Welcome. I think that you have to spend some time to learn about JavaScript and how it handle variables and assign values to them. – Rubén Jan 3 at 4:34
  • Okay great. Thanks Rubén, that sounds like a good starting point to get more familiar, rather than continuing to Frankenstein pieces of found code together. – Joe Jan 3 at 18:34

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.