Class FolderIterator
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
FolderIterator
此对象允许脚本遍历可能包含大量文件夹的集合。您可以通过 DriveApp、File 或 Folder 访问文件夹迭代器。
// Log the name of every folder in the user's Drive.
const folders = DriveApp.getFolders();
while (folders.hasNext()) {
const folder = folders.next();
Logger.log(folder.getName());
}
详细文档
getContinuationToken()
获取一个令牌,该令牌可用于稍后恢复此迭代。如果在一个执行中处理迭代器时超出最长执行时间,此方法会非常有用。续传令牌的有效期通常为一周。
返回
String - 续传令牌,可用于恢复此迭代,并包含生成令牌时迭代器中剩余的项。
hasNext()
确定调用 next() 是否会返回项。
返回
Boolean - 如果 next() 返回项,则为 true;否则为 false。
next()
获取文件或文件夹集合中的下一项。如果没有任何剩余项,则抛出异常。
返回
Folder - 集合中的下一项。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2026-04-13。
[null,null,["最后更新时间 (UTC):2026-04-13。"],[],["FolderIterator allows iterating over a large collection of folders. Key actions include using `hasNext()` to check for the next item and `next()` to retrieve it. `getContinuationToken()` provides a token to resume iteration later, helpful for large collections. The example shows how to log every folder's name in a user's Drive, demonstrating iteration through the folder collection. The iterator returns folder objects and can throw an exception if no items remain.\n"]]