我正在 Google 电子表格中使用脚本编辑器,并且我想在已创建的根文件夹内创建一个文件夹。我尝试遵循API的官方通知DriveApp ,但没有成功。 这是我的代码:
function createSubFolder(rootFolder,name){
DriveApp.getFoldersByName(rootFolder);
DriveApp.createFolder(name);
}
我也尝试过(按照这个旧的 post 使用旧版本的 DriveApp :即 DocsList):
function createSubFolder(rootFolder,name){
DriveApp.getFoldersByName(rootFolder).createFolder(name);
}
看起来很简单,但我不知道我错在哪里。 有谁知道怎么做吗?
谢谢
最佳答案
您需要为变量赋值。
function createSubFolder(rootFolder,name) {
var AllFoldersWithThisName = DriveApp.getFoldersByName(rootFolder);
var theFirstFolderWithThisName = AllFoldersWithThisName.next();
theFirstFolderWithThisName.createFolder(name);
};
在 Google 云端硬盘中,您可能有 1,000 个同名文件夹。文件名也是如此。
getFoldersByName()
方法返回:
FolderIterator — a collection of all folders in the user's Drive that have the given name
您需要从文件夹集合中获取其中一个文件夹。这是通过 next()
方法完成的。
关于google-apps-script - 如何使用谷歌应用程序脚本访问子文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37765394/