'when uploading google forms files to a custom folder only one file uploads

I m using a code found here

My goal, which is half way accomplished, is as follows:

  1. Create a sub folder based on respondent answer [done]

  2. Add all files in the form to said sub folder [so far is adding only one file of multiples that I request under the form]

  3. rename each file according to the type of file requested under question, and if multiple files under the same question are uploaded add, i.e.: "phototest" "phototest1"

function onFormSubmit(e) {
  const folderId = "1gvlYEr-CJwFVNZVipNkVNV3ussNvgfhR";  // Please set top folder ID of the destination folders.

  const form = FormApp.getActiveForm();
  const formResponses = form.getResponses();
  const itemResponses = formResponses[formResponses.length-1].getItemResponses();

  Utilities.sleep(3000); // This line might not be required.

  // Prepare the folder.
  const destFolder = DriveApp.getFolderById(folderId);
  const folderName = itemResponses[0].getResponse();
  const subFolder = destFolder.getFoldersByName(folderName);
  const folder = subFolder.hasNext() ? subFolder.next() : destFolder.createFolder(folderName);

  // Move files to the folder.
  itemResponses[2].getResponse().forEach(id => DriveApp.getFileById(id).moveTo(folder));
  }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source