.getId是由脚本创建的文件夹

时间:2016-01-20 22:20:29

标签: google-apps-script

我正在学习Google Script并制作一些脚本来查看可能的内容,我想创建一个文件夹并在其中创建一个文件或添加/更多其他项目。但我很困惑如何返回新文件夹的ID并写入该ID。我试过getId函数没有运气。 这是我在的地方:

function getStaticInfo_() {
  var staticInfo = {
    rezin8JobFolderSystemId: 'FolderID 1',  
    folderConfig1: 'TestClient#4'
  }       
  return staticInfo;
}


function CreateFolderAndSub() {
  //Get the static info.
  var static = getStaticInfo_();     
  var destination = DriveApp.getFolderById(static.rezin8JobFolderSystemId);      

  destination.createFolder(static.folderConfig1);

  var nextFolder1GetId = DriveApp.openFoldersByName(static.folderConfig1);
//  var nextFolder1Id = DriveApp.getFolderById(nextFolder1GetId);
  var nextFolder1Id = nextFolder1GetId.getId;

//  var body1 = formObject.sourceFolder;                    
//  var body2 = formObject.clientType;
//  var body3 = formObject.newProjectName;
//  var body4 = formObject.newClientName;
  var body5 = nextFolder1Id;
  var body = Logger.getLog();
  destination.createFile('Log','<b>sourceFolder = ' +body1 + '  END  ' + '<b>clientType = ' +body2 + '  END  </b>' + '<b>newProjectName = ' +body3 + '  END  </b>' + '<b>newClientName = ' +body4 + ' END  </b>' + '<b>nextFolder1Id = ' +body5 + ' END  </b>', MimeType.HTML);

}

如果有人能给我任何指示,将不胜感激。

由于

Alex

1 个答案:

答案 0 :(得分:0)

您的创建文件夹功能将返回创建的新文件夹destination.createFolder。所以你可以得到文件夹ID,

var nextFolder1 = destination.createFolder(static.folderConfig1);   
var nextFolder1Id = nextFolder1.getId();

从这里阅读更多内容 - createFolder

由于createFolder返回新文件夹,您可以在其上创建新文件;

nextFolder1.createFile('Log','<b>sourceFolder = ' +body1 + '  END  ' + '<b>clientType = ' +body2 + '  END  </b>' + '<b>newProjectName = ' +body3 + '  END  </b>' + '<b>newClientName = ' +body4 + ' END  </b>' + '<b>nextFolder1Id = ' +body5 + ' END  </b>', MimeType.HTML);

总而言之,

function CreateFolderAndSub() {
  //Get the static info.
  var static = getStaticInfo_();     
  var destination = DriveApp.getFolderById(static.rezin8JobFolderSystemId);      

  var nextFolder1 = destination.createFolder(static.folderConfig1);

  //var nextFolder1GetId = DriveApp.openFoldersByName(static.folderConfig1);

  var nextFolder1Id = nextFolder1.getId();

  var body1 = 'val1';//formObject.sourceFolder;                    
  var body2 = 'val2';//formObject.clientType;
  var body3 = 'val3';//formObject.newProjectName;
  var body4 = 'val4';//formObject.newClientName;
  var body5 = nextFolder1Id;
  var body = Logger.getLog();
  nextFolder1.createFile('Log','<b>sourceFolder = ' +body1 + '  END  ' + '<b>clientType = ' +body2 + '  END  </b>' + '<b>newProjectName = ' +body3 + '  END  </b>' + '<b>newClientName = ' +body4 + ' END  </b>' + '<b>nextFolder1Id = ' +body5 + ' END  </b>', MimeType.HTML);

}