Class FolderIterator
FolderIterator
An object that allows scripts to iterate over a potentially large collection of folders. Folder
iterators can be accessed from DriveApp
, a File
, or a 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());
}
Methods
Method | Return type | Brief description |
getContinuationToken() | String | Gets a token that can be used to resume this iteration at a later time. |
hasNext() | Boolean | Determines whether calling next() will return an item. |
next() | Folder | Gets the next item in the collection of files or folders. |
Detailed documentation
getContinuationToken()
Gets a token that can be used to resume this iteration at a later time. This method is useful
if processing an iterator in one execution would exceed the maximum execution time.
Continuation tokens are generally valid for one week.
Return
String
— a continuation token that can be used to resume this iteration with the items that
remained in the iterator when the token was generated
hasNext()
Determines whether calling next()
will return an item.
Return
Boolean
— true
if next()
will return an item; false
if not
next()
Gets the next item in the collection of files or folders. Throws an exception if no items
remain.
Return
Folder
— the next item in the collection
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-12-02 UTC.
[null,null,["Last updated 2024-12-02 UTC."],[[["`FolderIterator` enables scripts to iterate through a large collection of folders within Google Drive."],["It provides methods like `hasNext()` to check for more folders, `next()` to retrieve the next folder, and `getContinuationToken()` for handling lengthy iterations."],["Developers can utilize `FolderIterator` with `DriveApp`, `File`, or `Folder` objects to access and process folders programmatically."]]],["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"]]