谷歌应用程序脚本 - 如何检查文件夹是否存在

时间:2016-09-12 06:42:14

标签: javascript

我正在使用谷歌应用程序脚本,我想检查/ root / Received Files / folderName是否存在。如果不存在那么我想创建它。 但是

时总是显示错误
Subfolders.hasNext()

我该如何修复我的代码?

function getFolders(folderName)
{      
  var Subfolder;var Subfolders
  var folders = DriveApp.getFolders();     
 while (folders.hasNext()) {
   var folder = folders.next();
   if('Received Files' == folder.getName()) {         
     Subfolders=folder;
     while(Subfolders.hasNext()) ==> ERR
     {
        Subfolder=Subfolders.next();
        if(folderName == Subfolder.getName()) 
        {
          return Subfolder
        }
     }
   }
 }
  Subfolder=Subfolders.createFolder(folderName);
  return Subfolder;
}

1 个答案:

答案 0 :(得分:0)

你应该这样做:

Subfolders = folder.getFolders();

Subfolders = folder;