Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 复制时将日期添加到文件名_Google Apps Script - Fatal编程技术网

Google apps script 复制时将日期添加到文件名

Google apps script 复制时将日期添加到文件名,google-apps-script,Google Apps Script,我创建了一个脚本来创建Gdoc的副本: // Script-as-app template. function doGet(e) { //file has to be at least readable by the person running the script var fileId = e.parameters.fileId; if(!fileId){ //have a default fileId for testing. fileId = '1TzL

我创建了一个脚本来创建Gdoc的副本:

// Script-as-app template.
function doGet(e) {
  //file has to be at least readable by the person running the script
  var fileId = e.parameters.fileId;  
  if(!fileId){
    //have a default fileId for testing. 
    fileId = '1TzLleN93A0ibMhSQ3eenZ1dLC3RLB7T9XoIaRw8-pfk'; 
  }
  var newUrl = DocsList.getFileById(fileId).makeCopy('Filename').getUrl(); 
  return HtmlService.createHtmlOutput('<h1><a href="'+newUrl+'">Open Document</a></h1>');
}
//脚本作为应用程序模板。
函数doGet(e){
//文件必须至少能被运行脚本的人读取
var fileId=e.parameters.fileId;
如果(!fileId){
//具有用于测试的默认文件ID。
fileId='1TzLleN93A0ibMhSQ3eenZ1dLC3RLB7T9XoIaRw8 pfk';
}
var newUrl=DocsList.getFileById(fileId).makeCopy('Filename').getUrl();
返回HtmlService.createHtmlOutput(“”);
}
运行时如何将今天的日期dd/mm/yy添加到文件名

var newUrl = DocsList.getFileById(fileId).makeCopy('Filename').getUrl();
文件名在上面的“Filename”字符串中设置

获取旧文件名 我会使用DriveApp而不是DocsList

var theFileReference = DriveApp.getFileById(fileId);
var oldFileName = theFileReference.getName();
为新文件名创建一个变量。 制作副本:
var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth() + 1; //Months are zero based
var curr_year = d.getFullYear();

var theDate = curr_date + "-" + curr_month + "-" + curr_year);

var newFileName = oldFileName + theDate;
theFileReference.makeCopy(newFileName);