Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.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驱动器脚本中将文件添加到文件夹_Google Apps Script - Fatal编程技术网

Google apps script 在Google驱动器脚本中将文件添加到文件夹

Google apps script 在Google驱动器脚本中将文件添加到文件夹,google-apps-script,Google Apps Script,谷歌最终关闭了Docslist类,我的脚本本周停止运行。这是我的代码 var folder = DocsList.getFolderById('XXXXXXXXX'); var document = DocsList.getFileById(newSS.getId()); document.addtoFolder(folder); 所以我试着改用DriveApp。这是我切换到的代码 var folder = DriveApp.getFolderById('XXXXXXXXXX'

谷歌最终关闭了Docslist类,我的脚本本周停止运行。这是我的代码

  var folder = DocsList.getFolderById('XXXXXXXXX');
  var document = DocsList.getFileById(newSS.getId());
  document.addtoFolder(folder);
所以我试着改用DriveApp。这是我切换到的代码

  var folder = DriveApp.getFolderById('XXXXXXXXXX');
  var document = DriveApp.getFileById(newSS.getId());
  document.addFile(folder);

我收到一个错误“TypeError:在对象中找不到函数addFile”。我想我使用的addFile是错误的,但我不确定我到底做错了什么。有什么帮助吗?

好的,我知道了。我在使用“addFile”时遇到了问题。我需要它

folder.addFile(document);
不是


我不确定这是否会对其他人有所帮助,但我必须在脑海中想清楚,即使我将文件id存储在变量中,我仍然必须
getFileById()
。否则,我的脚本将不知道要添加到文件夹中的文件

var newDoc = DocumentApp.create('Testing Team Drive MoveTo').getId();
var teamDrive = DriveApp.getFolderById('xxxxxxxxxxxxxxxxxx');
var file = DriveApp.getFileById(newDoc);
var moveFile = teamDrive.addFile(file);
可能重复的
var newDoc = DocumentApp.create('Testing Team Drive MoveTo').getId();
var teamDrive = DriveApp.getFolderById('xxxxxxxxxxxxxxxxxx');
var file = DriveApp.getFileById(newDoc);
var moveFile = teamDrive.addFile(file);