Created
March 22, 2020 02:44
-
-
Save jakabo27/85a3e4cb0833e614265165774ee59c85 to your computer and use it in GitHub Desktop.
Renames a file submitted through a Google Form. Mine is set up to rename it to the email (before the @) and then the name the person typed in. So if jat5@g.clemson.edu submitted it with the name IronMan, the file would be "jat5 - IronMan.mp4"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function RenameFile() { | |
var form=FormApp.getActiveForm(); | |
var length=form.getResponses().length; // returns the total number of form submissions | |
//replace QUESTION NUMBER through the index of the question prompting the file upload - keep in mind that the first question has the index | |
var FILESUB = 0; //Where this is the question number starting at 0 that is the file submission. In my file it's the first question. Text description boxes don't count | |
var id=form.getResponses()[length-1].getItemResponses()[FILESUB].getResponse(); | |
// Logger.log('id = '+ id); | |
//get the email address and other information | |
var thisEmail=form.getResponses()[length-1].getRespondentEmail(); | |
thisEmail=thisEmail.split('@')[0]; //get just the first part before the @g.clemson.edu | |
// Logger.log('thisEmail = '+thisEmail); | |
var thisName = form.getResponses()[length-1].getItemResponses()[2].getResponse(); | |
var thisMajor = form.getResponses()[length-1].getItemResponses()[3].getResponse(); | |
var thisMinor = form.getResponses()[length-1].getItemResponses()[4].getResponse(); | |
var thisHometown = form.getResponses()[length-1].getItemResponses()[5].getResponse(); | |
var thisApplause = form.getResponses()[length-1].getItemResponses()[6].getResponse(); | |
// Logger.log('applause = '+thisApplause); //It's giving the string response... so I changed the response to start with abcd | |
var thisApplauseLetter = thisApplause.split(' - ')[0] | |
var time = new Date(); | |
var thisTimestamp = Utilities.formatDate(time, "GMT-04:00", "MM-dd hh-mm-a"); | |
// Logger.log('timestamp = '+thisTimestamp); | |
//access the uploaded file | |
var file=DriveApp.getFileById(id); | |
name = file.getName(); | |
//change the file name | |
var name = thisEmail+' - ' + thisName + ' - ' + thisApplauseLetter +' - ' + thisTimestamp; | |
Logger.log('New File Name = '+name) | |
file.setName(name); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment