Skip to content

Instantly share code, notes, and snippets.

@tm8r
Created October 25, 2016 11:21
Show Gist options
  • Save tm8r/cc25f6f4697803fecbd5daf43c6f0e2f to your computer and use it in GitHub Desktop.
Save tm8r/cc25f6f4697803fecbd5daf43c6f0e2f to your computer and use it in GitHub Desktop.
DriveFileCopy
function doGet(e) {
var fileId = e.parameter.fileId;
Logger.log("fileId:"+fileId);
if (!fileId){
Logger.log("invalid fileId.");
return HtmlService.createHtmlOutput(false);
}
var file = DriveApp.getFileById(fileId);
if (!file){
Logger.log("file is not found.");
return HtmlService.createHtmlOutput(false);
}
var parents = file.getParents();
var parent;
while (parents.hasNext()) {
parent = parents.next();
Logger.log(parent.getName());
break;
}
if(!parent){
}
var fileName = file.getName() + "_" + Utilities.formatDate( new Date(), 'JST', 'yyyy_MM_dd_HHmmss');
file.makeCopy(fileName, parent);
return HtmlService.createHtmlOutput(true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment