Object reference
Drive folder
A DriveApp.Folder is a container in Google Drive. Find one by name with DriveApp.getFoldersByName(name) or by ID with DriveApp.getFolderById(id).
DriveApp.FolderStart here
Get this object first
Find a folder by its exact name with DriveApp.getFoldersByName(), then check hasNext() before calling next(). When you have the folder ID from its Drive URL, use DriveApp.getFolderById(id) instead.
function showSavedAttachmentFolderName() {
const folders = DriveApp.getFoldersByName('Saved email attachments');
if (!folders.hasNext()) throw new Error('Create a Drive folder named Saved email attachments first.');
Logger.log(folders.next().getName());
} Then use it
Common actions
Choose an action, then open its example only when you need the code.
Count the files in a folder
This counts the files currently in the named folder without moving or changing them.
DriveApp.FolderShow example code
function countSavedAttachments() {
const folders = DriveApp.getFoldersByName('Saved email attachments');
if (!folders.hasNext()) throw new Error('Create a Drive folder named Saved email attachments first.');
const files = folders.next().getFiles();
let count = 0;
while (files.hasNext()) {
files.next();
count += 1;
}
Logger.log(count);
} List file names inside a folder
This iterates through getFiles() in the named folder and logs each file name without modifying any files.
DriveApp.FolderDriveApp.FileShow example code
function logFolderFileNames() {
const folders = DriveApp.getFoldersByName('Saved email attachments');
if (!folders.hasNext()) throw new Error('Create a Drive folder named Saved email attachments first.');
const files = folders.next().getFiles();
const names = [];
while (files.hasNext()) {
names.push(files.next().getName());
}
Logger.log(names.join(', ') || 'Folder is empty');
} Log the folder URL and subfolder count
This reads the Drive folder URL with getUrl() and counts direct child folders with getFolders() without creating or moving anything.
DriveApp.FolderShow example code
function logFolderUrlAndSubfolderCount() {
const folders = DriveApp.getFoldersByName('Saved email attachments');
if (!folders.hasNext()) throw new Error('Create a Drive folder named Saved email attachments first.');
const folder = folders.next();
const subfolders = folder.getFolders();
let count = 0;
while (subfolders.hasNext()) {
subfolders.next();
count += 1;
}
Logger.log(folder.getUrl() + ' (' + count + ' subfolders)');
} Technical reference
Exact names and signatures
Generated runtime and signature facts stay separate from the beginner actions above. Open method details only when you need them.
At a glance
- Service
- DriveApp
- Reference symbol
DriveApp.Folder- Object
Folder- Runtime
- From signature data
Methods and signatures
Browse 51 methods
addEditor
- addEditor(emailAddress: string): DriveApp.Folder
- addEditor(user: User): DriveApp.Folder
addEditors
- addEditors(emailAddresses: string[]): DriveApp.Folder
addFile
- addFile(child: DriveApp.File): DriveApp.Folder
addFolder
- addFolder(child: DriveApp.Folder): DriveApp.Folder
addViewer
- addViewer(emailAddress: string): DriveApp.Folder
- addViewer(user: User): DriveApp.Folder
addViewers
- addViewers(emailAddresses: string[]): DriveApp.Folder
createFile
- createFile(blob: BlobSource): DriveApp.File
- createFile(name: string, content: string): DriveApp.File
- createFile(name: string, content: string, mimeType: string): DriveApp.File
createFolder
- createFolder(name: string): DriveApp.Folder
createShortcut
- createShortcut(targetId: string): DriveApp.File
createShortcutForTargetIdAndResourceKey
- createShortcutForTargetIdAndResourceKey(targetId: string, targetResourceKey: string): DriveApp.File
getAccess
- getAccess(email: string): DriveApp.Permission
- getAccess(user: User): DriveApp.Permission
getDateCreated
- getDateCreated(): Date
getDescription
- getDescription(): string
getEditors
- getEditors(): User[]
getFiles
- getFiles(): DriveApp.FileIterator
getFilesByName
- getFilesByName(name: string): DriveApp.FileIterator
getFilesByType
- getFilesByType(mimeType: string): DriveApp.FileIterator
getFolders
- getFolders(): DriveApp.FolderIterator
getFoldersByName
- getFoldersByName(name: string): DriveApp.FolderIterator
getId
- getId(): string
getLastUpdated
- getLastUpdated(): Date
getName
- getName(): string
getOwner
- getOwner(): User
getParents
- getParents(): DriveApp.FolderIterator
getResourceKey
- getResourceKey(): string
getSecurityUpdateEligible
- getSecurityUpdateEligible(): boolean
getSecurityUpdateEnabled
- getSecurityUpdateEnabled(): boolean
getSharingAccess
- getSharingAccess(): DriveApp.Access
getSharingPermission
- getSharingPermission(): DriveApp.Permission
getSize
- getSize(): number
getUrl
- getUrl(): string
getViewers
- getViewers(): User[]
isShareableByEditors
- isShareableByEditors(): boolean
isStarred
- isStarred(): boolean
isTrashed
- isTrashed(): boolean
moveTo
- moveTo(destination: DriveApp.Folder): DriveApp.Folder
removeEditor
- removeEditor(emailAddress: string): DriveApp.Folder
- removeEditor(user: User): DriveApp.Folder
removeFile
- removeFile(child: DriveApp.File): DriveApp.Folder
removeFolder
- removeFolder(child: DriveApp.Folder): DriveApp.Folder
removeViewer
- removeViewer(emailAddress: string): DriveApp.Folder
- removeViewer(user: User): DriveApp.Folder
revokePermissions
- revokePermissions(emailAddress: string): DriveApp.Folder
- revokePermissions(user: User): DriveApp.Folder
searchFiles
- searchFiles(query: string): DriveApp.FileIterator
searchFolders
- searchFolders(query: string): DriveApp.FolderIterator
setDescription
- setDescription(description: string): DriveApp.Folder
setName
- setName(name: string): DriveApp.Folder
setOwner
- setOwner(emailAddress: string): DriveApp.Folder
- setOwner(user: User): DriveApp.Folder
setSecurityUpdateEnabled
- setSecurityUpdateEnabled(enabled: boolean): DriveApp.Folder
setShareableByEditors
- setShareableByEditors(shareable: boolean): DriveApp.Folder
setSharing
- setSharing(accessType: DriveApp.Access, permissionType: DriveApp.Permission): DriveApp.Folder
setStarred
- setStarred(starred: boolean): DriveApp.Folder
setTrashed
- setTrashed(trashed: boolean): DriveApp.Folder
Need the whole workflow?
Return to a task guide
Task guides cover setup, permissions, expected results, and troubleshooting as well as object methods.
Browse Google Drive tasks