Javascript 谷歌应用程序为创建的文档指定路径

Javascript 谷歌应用程序为创建的文档指定路径,javascript,path,google-apps-script,document,Javascript,Path,Google Apps Script,Document,我试图根据谷歌应用程序中的一些用户信息生成文档 我有如下代码(简化): 然而,我实际上似乎无法保存到除“根”谷歌驱动器目录之外的任何地方。换句话说,我想将文档保存在某个子文件夹中。谷歌API有这个功能吗?我检查了文档API,但没有结果() 希望这一点不像我担心的那么明显 提前感谢。调用DocumentApp.create时,路径的概念不存在,即斜线和点仅解释为文件名中的另一个字符。您需要做的是将该类与DocumentApp类一起使用。如下所示(未经测试): 把上面的答案再充实一点。您需要使用Dr

我试图根据谷歌应用程序中的一些用户信息生成文档

我有如下代码(简化):

然而,我实际上似乎无法保存到除“根”谷歌驱动器目录之外的任何地方。换句话说,我想将文档保存在某个子文件夹中。谷歌API有这个功能吗?我检查了文档API,但没有结果()

希望这一点不像我担心的那么明显


提前感谢。

调用DocumentApp.create时,路径的概念不存在,即斜线和点仅解释为文件名中的另一个字符。您需要做的是将该类与DocumentApp类一起使用。如下所示(未经测试):


把上面的答案再充实一点。您需要使用DriveApp类获取文件夹迭代器,然后获取迭代器中的实际文件夹(应该是唯一的项)。看


别忘了从根文件夹中删除。。。除非您希望将其同时保存在“我的驱动器”和所需文件夹中“创建文件夹”部分仅创建一个文件夹,否则要创建包含多个子文件夹级别的完整路径,脚本将复杂得多。
var titleAndPath = "./some/other/path/bar.doc"
var info = "foo";
var currentDoc = DocumentApp.create(titleAndPath);
var title = currentDoc.appendParagraph(info);
var title = "bar.doc";
var doc = DocumentApp.create ( title );
var docId = doc.getId ();                     // retrieve the document unique id
var docFile = DriveApp.getFileById ( docId ); // then get the corresponding file
// Use the DriveApp folder creation and navigation mechanisms either:
// - to get to your existing folder, or
// - to create the folder path you need.
var folder = …
folder.addFile ( docFile );
var title = "bar.doc";
  var folderTitle = "GoogleApplicationScriptTesting" ;
  var doc = DocumentApp.create ( title );
  var docId = doc.getId ();                     // retrieve the document unique id
  var docFile = DriveApp.getFileById ( docId ); // then get the corresponding file


  // Use the DriveApp folder creation and navigation mechanisms either:
  // getFoldersByName returns a folderIterator so you need to do additional checking


 var folderIter = DriveApp.getFoldersByName(folderTitle);


  if(folderIter.hasNext()) {
    Logger.log('Folder already exists');
    var folder = folders.next();
  } 

  else{
    var folder = DriveApp.createFolder(folderTitle);
    Logger.log('New folder created!');
  }
  folder.addFile ( docFile );

}