Skip to content

Instantly share code, notes, and snippets.

@IanMcT
Created February 22, 2017 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IanMcT/2534c40ab12b2d9b1739aa719d01f11b to your computer and use it in GitHub Desktop.
Save IanMcT/2534c40ab12b2d9b1739aa719d01f11b to your computer and use it in GitHub Desktop.
Google Script code for copying a file for every student in the class.
function myFunction() {
// Usercan copy the current file with a new name.
var ui = DocumentApp.getUi();
var newFileName = "";
while (newFileName != "Q"){
if (newFileName != "Q")
{
Logger.log('File name is not Q');
}else
{
Logger.log('File name is Q');
}
var response = ui.prompt('File Copier', 'Type a new and click yes to copy the current file with that name', ui.ButtonSet.YES_NO);
// Process the user's response.
if (response.getSelectedButton() == ui.Button.YES) {
//copy file
// Get the document to which this script is bound.
var doc = DocumentApp.getActiveDocument();
var destFolder = DriveApp.getFolderById(doc.getId());
DriveApp.getFileById(doc.getId()).makeCopy(response.getResponseText())
}
else if (response.getSelectedButton() == ui.Button.NO) {
newFileName = "Q";
} else {
Logger.log('The user clicked the close button in the dialog\'s title bar.');
newFileName = "Q";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment