Drive Service

  • The Drive service in Apps Script allows scripts to manage files and folders in Google Drive.

  • For enhanced features, including shared drive access, use the advanced Drive service.

  • If using a standard Cloud project, the Drive API must be manually enabled.

  • Google Workspace Administrators can disable the Drive SDK, affecting script access unless the add-on is domain-wide installed or the client is allowlisted.

Drive

This service lets scripts create, find, and modify files and folders inGoogle Drive. Although the built-in Drive service is easier to use, it has some limitations. For the most up-to-date features and support, and to access files or folders in shared drives, use theadvanced Drive service.

If your script uses astandard Cloud project instead of a default Cloud project, you must manually turn on the Drive API. In your standard Cloud project, turn on the Drive API:

Turn on the Drive API

The following code sample shows how to log the names of each file in the user'sMy Drive folder:
//Logsthenameofeveryfileintheuser's Drive.varfiles=DriveApp.getFiles();while(files.hasNext()){varfile=files.next();console.log(file.getName());}

Note: Google Workspace Administratorscan turn off theDrive SDKfor their domain, which prevents their users from installing and using GoogleDrive apps. This setting also prevents users from usingApps Script scripts, web apps and add-ons that use theDriveservice orAdvanced Drive Service(even if the add-on or web app was installed before the admin turned off theDrive SDK).

However, if an add-on using the Drive service is published for domain-wide installationand is installed by the administrator for some or all users in the domain, or any script thathas itsOAuth client allowlistedby the domain administrator, the add-on functions for those users even if theDrive SDK is turned off in the domain.

Classes

NameBrief description
AccessAn enum representing classes of users who can access a file or folder, besides any individualusers who have been explicitly given access.
DriveAppAllows scripts to create, find, and modify files and folders in Google Drive.
FileA file in Google Drive.
FileIteratorAn iterator that allows scripts to iterate over a potentially large collection of files.
FolderA folder in Google Drive.
FolderIteratorAn object that allows scripts to iterate over a potentially large collection of folders.
PermissionAn enum representing the permissions granted to users who can access a file or folder, besidesany individual users who have been explicitly given access.
UserA user associated with a file in Google Drive.

Access

Properties

PropertyTypeDescription
ANYONEEnumAnyone on the Internet can find and access.
ANYONE_WITH_LINKEnumAnyone who has the link can access.
DOMAINEnumPeople in your domain can find and access.
DOMAIN_WITH_LINKEnumPeople in your domain who have the link can access.
PRIVATEEnumOnly people explicitly granted permission can access.

DriveApp

Properties

PropertyTypeDescription
AccessAccessAn enum representing classes of users who can access a file or folder, besides any individualusers who have been explicitly given access.
PermissionPermissionAn enum representing the permissions granted to users who can access a file or folder, besidesany individual users who have been explicitly given access.

Methods

MethodReturn typeBrief description
continueFileIterator(continuationToken)FileIteratorResumes a file iteration using a continuation token from a previous iterator.
continueFolderIterator(continuationToken)FolderIteratorResumes a folder iteration using a continuation token from a previous iterator.
createFile(blob)FileCreates a file in the root of the user's Drive from a givenBlob of arbitrary data.
createFile(name, content)FileCreates a text file in the root of the user's Drive with the given name and contents.
createFile(name, content, mimeType)FileCreates a file in the root of the user's Drive with the given name, contents, and MIME type.
createFolder(name)FolderCreates a folder in the root of the user's Drive with the given name.
createShortcut(targetId)FileCreates a shortcut to the provided Drive item ID, and returns it.
createShortcutForTargetIdAndResourceKey(targetId, targetResourceKey)FileCreates a shortcut to the provided Drive item ID and resource key, and returns it.
enforceSingleParent(value)voidEnables or disables enforceSingleParent behavior for all calls affecting item parents.
getFileById(id)FileGets the file with the given ID.
getFileByIdAndResourceKey(id, resourceKey)FileGets the file with the given ID and resource key.
getFiles()FileIteratorGets a collection of all files in the user's Drive.
getFilesByName(name)FileIteratorGets a collection of all files in the user's Drive that have the given name.
getFilesByType(mimeType)FileIteratorGets a collection of all files in the user's Drive that have the given MIME type.
getFolderById(id)FolderGets the folder with the given ID.
getFolderByIdAndResourceKey(id, resourceKey)FolderGets the folder with the given ID and resource key.
getFolders()FolderIteratorGets a collection of all folders in the user's Drive.
getFoldersByName(name)FolderIteratorGets a collection of all folders in the user's Drive that have the given name.
getRootFolder()FolderGets the folder at the root of the user's Drive.
getStorageLimit()IntegerGets the number of bytes the user is allowed to store in Drive.
getStorageUsed()IntegerGets the number of bytes the user is currently storing in Drive.
getTrashedFiles()FileIteratorGets a collection of all the files in the trash of the user's Drive.
getTrashedFolders()FolderIteratorGets a collection of all the folders in the trash of the user's Drive.
searchFiles(params)FileIteratorGets a collection of all files in the user's Drive that match the given searchcriteria.
searchFolders(params)FolderIteratorGets a collection of all folders in the user's Drive that match the given searchcriteria.

File

Methods

MethodReturn typeBrief description
addCommenter(emailAddress)FileAdd the given user to the list of commenters for theFile.
addCommenter(user)FileAdd the given user to the list of commenters for theFile.
addCommenters(emailAddresses)FileAdd the given array of users to the list of commenters for theFile.
addEditor(emailAddress)FileAdds the given user to the list of editors for theFile.
addEditor(user)FileAdds the given user to the list of editors for theFile.
addEditors(emailAddresses)FileAdds the given array of users to the list of editors for theFile.
addViewer(emailAddress)FileAdds the given user to the list of viewers for theFile.
addViewer(user)FileAdds the given user to the list of viewers for theFile.
addViewers(emailAddresses)FileAdds the given array of users to the list of viewers for theFile.
getAccess(email)PermissionGets the permission granted to a specific user.
getAccess(user)PermissionGets the permission granted to a specific user.
getAs(contentType)BlobReturn the data inside this object as a blob converted to the specified content type.
getBlob()BlobReturn the data inside this object as a blob.
getDateCreated()DateGets the date theFile was created.
getDescription()StringGets the description for theFile.
getDownloadUrl()StringGets the URL that can be used to download the file.
getEditors()User[]Gets the list of editors for thisFile.
getId()StringGets the ID of theFile.
getLastUpdated()DateGets the date theFile was last updated.
getMimeType()StringGets the MIME type of the file.
getName()StringGets the name of theFile.
getOwner()UserGets the file owner.
getParents()FolderIteratorGets a collection of folders that are immediate parents of theFile.
getResourceKey()StringGets the resource key of theFile that is required to access items thathave been shared using a link.
getSecurityUpdateEligible()BooleanGets whether thisFile is eligible to apply the security update thatrequires a resource key for access when it's shared using a link.
getSecurityUpdateEnabled()BooleanGets whether thisFile requires a resource key for access when it'sshared using a link.
getSharingAccess()AccessGets which class of users can access theFile, besides any individualusers who have been explicitly given access.
getSharingPermission()PermissionGets the permission granted to those users who can access theFile,besides any individual users who have been explicitly given access.
getSize()IntegerGets the number of bytes used to store theFile in Drive.
getTargetId()StringIf this is a Shortcut, returns the ID of the item it points to.
getTargetMimeType()StringIf this is a Shortcut, returns the mime type of the item it points to.
getTargetResourceKey()StringIf the file is a shortcut, returns the resource key of the item it points to.
getThumbnail()Blob|nullGets a thumbnail image for the file, ornull if no thumbnail exists.
getUrl()StringGets the URL that can be used to open theFile in a Google App likeDrive or Docs.
getViewers()User[]Gets the list of viewers and commenters for thisFile.
isShareableByEditors()BooleanDetermines whether users with edit permissions to theFile are allowed toshare with other users or change the permissions.
isStarred()BooleanDetermines whether theFile has been starred in the user's Drive.
isTrashed()BooleanDetermines whether theFile is in the trash of the user's Drive.
makeCopy()FileCreates a copy of the file.
makeCopy(destination)FileCreates a copy of the file in the destination directory.
makeCopy(name)FileCreates a copy of the file and names it with the name provided.
makeCopy(name, destination)FileCreates a copy of the file in the destination directory and names it with the name provided.
moveTo(destination)FileMoves this item to the provided destination folder.
removeCommenter(emailAddress)FileRemoves the given user from the list of commenters for theFile.
removeCommenter(user)FileRemoves the given user from the list of commenters for theFile.
removeEditor(emailAddress)FileRemoves the given user from the list of editors for theFile.
removeEditor(user)FileRemoves the given user from the list of editors for theFile.
removeViewer(emailAddress)FileRemoves the given user from the list of viewers and commenters for theFile.
removeViewer(user)FileRemoves the given user from the list of viewers and commenters for theFile.
revokePermissions(emailAddress)FileRevokes the access to theFile granted to the given user.
revokePermissions(user)FileRevokes the access to theFile granted to the given user.
setContent(content)FileOverwrites the content of the file with a given replacement.
setDescription(description)FileSets the description for theFile.
setName(name)FileSets the name of theFile.
setOwner(emailAddress)FileChanges the owner of theFile.
setOwner(user)FileChanges the owner of theFile.
setSecurityUpdateEnabled(enabled)FileSets whether theFile requires a resource key for access when it'sshared using a link.
setShareableByEditors(shareable)FileSets whether users with edit permissions to theFile are allowed to sharewith other users or change the permissions.
setSharing(accessType, permissionType)FileSets which class of users can access theFile and what permissionsthose users are granted, besides any individual users who have been explicitly given access.
setStarred(starred)FileSets whether theFile is starred in the user's Drive.
setTrashed(trashed)FileSets whether theFile is in the trash of the user's Drive.

FileIterator

Methods

MethodReturn typeBrief description
getContinuationToken()StringGets a token that can be used to resume this iteration at a later time.
hasNext()BooleanDetermines whether callingnext() will return an item.
next()FileGets the next item in the collection of files or folders.

Folder

Methods

MethodReturn typeBrief description
addEditor(emailAddress)FolderAdds the given user to the list of editors for theFolder.
addEditor(user)FolderAdds the given user to the list of editors for theFolder.
addEditors(emailAddresses)FolderAdds the given array of users to the list of editors for theFolder.
addViewer(emailAddress)FolderAdds the given user to the list of viewers for theFolder.
addViewer(user)FolderAdds the given user to the list of viewers for theFolder.
addViewers(emailAddresses)FolderAdds the given array of users to the list of viewers for theFolder.
createFile(blob)FileCreates a file in the current folder from a givenBlob of arbitrary data.
createFile(name, content)FileCreates a text file in the current folder with the given name and contents.
createFile(name, content, mimeType)FileCreates a file in the current folder with the given name, contents, and MIME type.
createFolder(name)FolderCreates a folder in the current folder with the given name.
createShortcut(targetId)FileCreates a shortcut to the provided Drive item ID, and returns it.
createShortcutForTargetIdAndResourceKey(targetId, targetResourceKey)FileCreates a shortcut to the provided Drive item ID and resource key, and returns it.
getAccess(email)PermissionGets the permission granted to a specific user.
getAccess(user)PermissionGets the permission granted to a specific user.
getDateCreated()DateGets the date theFolder was created.
getDescription()StringGets the description for theFolder.
getEditors()User[]Gets the list of editors for thisFolder.
getFiles()FileIteratorGets a collection of all files that are children of the current folder.
getFilesByName(name)FileIteratorGets a collection of all files that are children of the current folder and have the given name.
getFilesByType(mimeType)FileIteratorGets a collection of all files that are children of the current folder and have the given MIME type.
getFolders()FolderIteratorGets a collection of all folders that are children of the current folder.
getFoldersByName(name)FolderIteratorGets a collection of all folders that are children of the current folder and have the given name.
getId()StringGets the ID of theFolder.
getLastUpdated()DateGets the date theFolder was last updated.
getName()StringGets the name of theFolder.
getOwner()UserGets the owner of thisFolder.
getParents()FolderIteratorGets a collection of folders that are immediate parents of theFolder.
getResourceKey()StringGets the resource key of theFolder that is required to access items thathave been shared using a link.
getSecurityUpdateEligible()BooleanGets whether thisFolder is eligible to apply the security update thatrequires a resource key for access when it's shared using a link.
getSecurityUpdateEnabled()BooleanGets whether thisFolder requires a resource key for access when it'sshared using a link.
getSharingAccess()AccessGets which class of users can access theFolder, besides any individualusers who have been explicitly given access.
getSharingPermission()PermissionGets the permission granted to those users who can access theFolder,besides any individual users who have been explicitly given access.
getSize()IntegerGets the number of bytes used to store theFolder in Drive.
getUrl()StringGets the URL that can be used to open theFolder in a Google App likeDrive or Docs.
getViewers()User[]Gets the list of viewers and commenters for thisFolder.
isShareableByEditors()BooleanDetermines whether users with edit permissions to theFolder are allowed toshare with other users or change the permissions.
isStarred()BooleanDetermines whether theFolder has been starred in the user's Drive.
isTrashed()BooleanDetermines whether theFolder is in the trash of the user's Drive.
moveTo(destination)FolderMoves this item to the provided destination folder.
removeEditor(emailAddress)FolderRemoves the given user from the list of editors for theFolder.
removeEditor(user)FolderRemoves the given user from the list of editors for theFolder.
removeViewer(emailAddress)FolderRemoves the given user from the list of viewers and commenters for theFolder.
removeViewer(user)FolderRemoves the given user from the list of viewers and commenters for theFolder.
revokePermissions(emailAddress)FolderRevokes the access to theFolder granted to the given user.
revokePermissions(user)FolderRevokes the access to theFolder granted to the given user.
searchFiles(params)FileIteratorGets a collection of all files that are children of the current folder and match the given searchcriteria.
searchFolders(params)FolderIteratorGets a collection of all folders that are children of the current folder and match the given searchcriteria.
setDescription(description)FolderSets the description for theFolder.
setName(name)FolderSets the name of theFolder.
setOwner(emailAddress)FolderChanges the owner of theFolder.
setOwner(user)FolderChanges the owner of theFolder.
setSecurityUpdateEnabled(enabled)FolderSets whether theFolder requires a resource key for access when it'sshared using a link.
setShareableByEditors(shareable)FolderSets whether users with edit permissions to theFolder are allowed to sharewith other users or change the permissions.
setSharing(accessType, permissionType)FolderSets which class of users can access theFolder and what permissionsthose users are granted, besides any individual users who have been explicitly given access.
setStarred(starred)FolderSets whether theFolder is starred in the user's Drive.
setTrashed(trashed)FolderSets whether theFolder is in the trash of the user's Drive.

FolderIterator

Methods

MethodReturn typeBrief description
getContinuationToken()StringGets a token that can be used to resume this iteration at a later time.
hasNext()BooleanDetermines whether callingnext() will return an item.
next()FolderGets the next item in the collection of files or folders.

Permission

Properties

PropertyTypeDescription
VIEWEnumUsers who can access the file or folder are able only to view it or copy it.
EDITEnumUsers who can access the file or folder are able to edit it.
COMMENTEnumUsers who can access the file or folder are able only to view it, copy it, or comment on it.
OWNEREnumThe user owns the file or folder.
ORGANIZEREnumUsers who can organize files and folders within a shared drive.
FILE_ORGANIZEREnumUsers who can edit, trash, and move content within a shared drive.
NONEEnumThe user does not have any permissions for the file or folder.

User

Methods

MethodReturn typeBrief description
getDomain()String|nullGets the domain name associated with the user's account.
getEmail()String|nullGets the user's email address.
getName()String|nullGets the user's name.
getPhotoUrl()String|nullGets the URL for the user's photo.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-11 UTC.