I have a form contains questions
It heavily depends on how your form looks like.
Here is an example how it could be done.
Suppose you have a very simply form like this:
It has two 'namedValues': Folder and File, they will be used in the script below.
Next step: You have to add a 'linked' spreadsheet to the form.
In this spreadsheet you have to add this script:
// names and IDs of your destination folders
var folders = {
'aaa' : '###', // <-- you have to change ### with a real ID
'bbb' : '###',
'ccc' : '###'
}
function move_file_to_folder(e) {
// get folder ID from folders object
var folder_id = folders[e.namedValues['Folder'][0]]; // <-- the name from the named value 'Folder'
// get file ID from the form
var file_id = e.namedValues['File'][0].split('id=')[1]; // <-- the url from the named value 'File'
// move the file into the folder
DriveApp.getFileById(file_id).moveTo(DriveApp.getFolderById(folder_id));
}
// this function should be run just once to install the trigger
function install_OnFormSubmitTrigger() {
var ss = SpreadsheetApp.getActive();
ScriptApp.newTrigger('move_file_to_folder')
.forSpreadsheet(ss)
.onFormSubmit()
.create();
}
After that you have to run the function install_OnFormSubmitTrigger() to install the trigger.
Probably it makes sense to run the function move_file_to_folder() as well, in order to get the propper access. It will get you an error. Don't mind. Keep calm and carry on.
Now, every time you submit the form the uploaded file will go into a folder with respective name ('aaa', 'bbb', 'ccc' in my example).