Drive Service Stay organized with collections Save and categorize content based on your preferences.
Page Summary
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.
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:
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
| Name | Brief description |
|---|---|
Access | An enum representing classes of users who can access a file or folder, besides any individualusers who have been explicitly given access. |
Drive | Allows scripts to create, find, and modify files and folders in Google Drive. |
File | A file in Google Drive. |
File | An iterator that allows scripts to iterate over a potentially large collection of files. |
Folder | A folder in Google Drive. |
Folder | An object that allows scripts to iterate over a potentially large collection of folders. |
Permission | An enum representing the permissions granted to users who can access a file or folder, besidesany individual users who have been explicitly given access. |
User | A user associated with a file in Google Drive. |
Access
Properties
| Property | Type | Description |
|---|---|---|
ANYONE | Enum | Anyone on the Internet can find and access. |
ANYONE_WITH_LINK | Enum | Anyone who has the link can access. |
DOMAIN | Enum | People in your domain can find and access. |
DOMAIN_WITH_LINK | Enum | People in your domain who have the link can access. |
PRIVATE | Enum | Only people explicitly granted permission can access. |
DriveApp
Properties
| Property | Type | Description |
|---|---|---|
Access | Access | An enum representing classes of users who can access a file or folder, besides any individualusers who have been explicitly given access. |
Permission | Permission | An enum representing the permissions granted to users who can access a file or folder, besidesany individual users who have been explicitly given access. |
Methods
| Method | Return type | Brief description |
|---|---|---|
continue | File | Resumes a file iteration using a continuation token from a previous iterator. |
continue | Folder | Resumes a folder iteration using a continuation token from a previous iterator. |
create | File | Creates a file in the root of the user's Drive from a givenBlob of arbitrary data. |
create | File | Creates a text file in the root of the user's Drive with the given name and contents. |
create | File | Creates a file in the root of the user's Drive with the given name, contents, and MIME type. |
create | Folder | Creates a folder in the root of the user's Drive with the given name. |
create | File | Creates a shortcut to the provided Drive item ID, and returns it. |
create | File | Creates a shortcut to the provided Drive item ID and resource key, and returns it. |
enforce | void | Enables or disables enforceSingleParent behavior for all calls affecting item parents. |
get | File | Gets the file with the given ID. |
get | File | Gets the file with the given ID and resource key. |
get | File | Gets a collection of all files in the user's Drive. |
get | File | Gets a collection of all files in the user's Drive that have the given name. |
get | File | Gets a collection of all files in the user's Drive that have the given MIME type. |
get | Folder | Gets the folder with the given ID. |
get | Folder | Gets the folder with the given ID and resource key. |
get | Folder | Gets a collection of all folders in the user's Drive. |
get | Folder | Gets a collection of all folders in the user's Drive that have the given name. |
get | Folder | Gets the folder at the root of the user's Drive. |
get | Integer | Gets the number of bytes the user is allowed to store in Drive. |
get | Integer | Gets the number of bytes the user is currently storing in Drive. |
get | File | Gets a collection of all the files in the trash of the user's Drive. |
get | Folder | Gets a collection of all the folders in the trash of the user's Drive. |
search | File | Gets a collection of all files in the user's Drive that match the given searchcriteria. |
search | Folder | Gets a collection of all folders in the user's Drive that match the given searchcriteria. |
File
Methods
| Method | Return type | Brief description |
|---|---|---|
add | File | Add the given user to the list of commenters for theFile. |
add | File | Add the given user to the list of commenters for theFile. |
add | File | Add the given array of users to the list of commenters for theFile. |
add | File | Adds the given user to the list of editors for theFile. |
add | File | Adds the given user to the list of editors for theFile. |
add | File | Adds the given array of users to the list of editors for theFile. |
add | File | Adds the given user to the list of viewers for theFile. |
add | File | Adds the given user to the list of viewers for theFile. |
add | File | Adds the given array of users to the list of viewers for theFile. |
get | Permission | Gets the permission granted to a specific user. |
get | Permission | Gets the permission granted to a specific user. |
get | Blob | Return the data inside this object as a blob converted to the specified content type. |
get | Blob | Return the data inside this object as a blob. |
get | Date | Gets the date theFile was created. |
get | String | Gets the description for theFile. |
get | String | Gets the URL that can be used to download the file. |
get | User[] | Gets the list of editors for thisFile. |
get | String | Gets the ID of theFile. |
get | Date | Gets the date theFile was last updated. |
get | String | Gets the MIME type of the file. |
get | String | Gets the name of theFile. |
get | User | Gets the file owner. |
get | Folder | Gets a collection of folders that are immediate parents of theFile. |
get | String | Gets the resource key of theFile that is required to access items thathave been shared using a link. |
get | Boolean | Gets whether thisFile is eligible to apply the security update thatrequires a resource key for access when it's shared using a link. |
get | Boolean | Gets whether thisFile requires a resource key for access when it'sshared using a link. |
get | Access | Gets which class of users can access theFile, besides any individualusers who have been explicitly given access. |
get | Permission | Gets the permission granted to those users who can access theFile,besides any individual users who have been explicitly given access. |
get | Integer | Gets the number of bytes used to store theFile in Drive. |
get | String | If this is a Shortcut, returns the ID of the item it points to. |
get | String | If this is a Shortcut, returns the mime type of the item it points to. |
get | String | If the file is a shortcut, returns the resource key of the item it points to. |
get | Blob|null | Gets a thumbnail image for the file, ornull if no thumbnail exists. |
get | String | Gets the URL that can be used to open theFile in a Google App likeDrive or Docs. |
get | User[] | Gets the list of viewers and commenters for thisFile. |
is | Boolean | Determines whether users with edit permissions to theFile are allowed toshare with other users or change the permissions. |
is | Boolean | Determines whether theFile has been starred in the user's Drive. |
is | Boolean | Determines whether theFile is in the trash of the user's Drive. |
make | File | Creates a copy of the file. |
make | File | Creates a copy of the file in the destination directory. |
make | File | Creates a copy of the file and names it with the name provided. |
make | File | Creates a copy of the file in the destination directory and names it with the name provided. |
move | File | Moves this item to the provided destination folder. |
remove | File | Removes the given user from the list of commenters for theFile. |
remove | File | Removes the given user from the list of commenters for theFile. |
remove | File | Removes the given user from the list of editors for theFile. |
remove | File | Removes the given user from the list of editors for theFile. |
remove | File | Removes the given user from the list of viewers and commenters for theFile. |
remove | File | Removes the given user from the list of viewers and commenters for theFile. |
revoke | File | Revokes the access to theFile granted to the given user. |
revoke | File | Revokes the access to theFile granted to the given user. |
set | File | Overwrites the content of the file with a given replacement. |
set | File | Sets the description for theFile. |
set | File | Sets the name of theFile. |
set | File | Changes the owner of theFile. |
set | File | Changes the owner of theFile. |
set | File | Sets whether theFile requires a resource key for access when it'sshared using a link. |
set | File | Sets whether users with edit permissions to theFile are allowed to sharewith other users or change the permissions. |
set | File | Sets which class of users can access theFile and what permissionsthose users are granted, besides any individual users who have been explicitly given access. |
set | File | Sets whether theFile is starred in the user's Drive. |
set | File | Sets whether theFile is in the trash of the user's Drive. |
FileIterator
Methods
| Method | Return type | Brief description |
|---|---|---|
get | String | Gets a token that can be used to resume this iteration at a later time. |
has | Boolean | Determines whether callingnext() will return an item. |
next() | File | Gets the next item in the collection of files or folders. |
Folder
Methods
| Method | Return type | Brief description |
|---|---|---|
add | Folder | Adds the given user to the list of editors for theFolder. |
add | Folder | Adds the given user to the list of editors for theFolder. |
add | Folder | Adds the given array of users to the list of editors for theFolder. |
add | Folder | Adds the given user to the list of viewers for theFolder. |
add | Folder | Adds the given user to the list of viewers for theFolder. |
add | Folder | Adds the given array of users to the list of viewers for theFolder. |
create | File | Creates a file in the current folder from a givenBlob of arbitrary data. |
create | File | Creates a text file in the current folder with the given name and contents. |
create | File | Creates a file in the current folder with the given name, contents, and MIME type. |
create | Folder | Creates a folder in the current folder with the given name. |
create | File | Creates a shortcut to the provided Drive item ID, and returns it. |
create | File | Creates a shortcut to the provided Drive item ID and resource key, and returns it. |
get | Permission | Gets the permission granted to a specific user. |
get | Permission | Gets the permission granted to a specific user. |
get | Date | Gets the date theFolder was created. |
get | String | Gets the description for theFolder. |
get | User[] | Gets the list of editors for thisFolder. |
get | File | Gets a collection of all files that are children of the current folder. |
get | File | Gets a collection of all files that are children of the current folder and have the given name. |
get | File | Gets a collection of all files that are children of the current folder and have the given MIME type. |
get | Folder | Gets a collection of all folders that are children of the current folder. |
get | Folder | Gets a collection of all folders that are children of the current folder and have the given name. |
get | String | Gets the ID of theFolder. |
get | Date | Gets the date theFolder was last updated. |
get | String | Gets the name of theFolder. |
get | User | Gets the owner of thisFolder. |
get | Folder | Gets a collection of folders that are immediate parents of theFolder. |
get | String | Gets the resource key of theFolder that is required to access items thathave been shared using a link. |
get | Boolean | Gets whether thisFolder is eligible to apply the security update thatrequires a resource key for access when it's shared using a link. |
get | Boolean | Gets whether thisFolder requires a resource key for access when it'sshared using a link. |
get | Access | Gets which class of users can access theFolder, besides any individualusers who have been explicitly given access. |
get | Permission | Gets the permission granted to those users who can access theFolder,besides any individual users who have been explicitly given access. |
get | Integer | Gets the number of bytes used to store theFolder in Drive. |
get | String | Gets the URL that can be used to open theFolder in a Google App likeDrive or Docs. |
get | User[] | Gets the list of viewers and commenters for thisFolder. |
is | Boolean | Determines whether users with edit permissions to theFolder are allowed toshare with other users or change the permissions. |
is | Boolean | Determines whether theFolder has been starred in the user's Drive. |
is | Boolean | Determines whether theFolder is in the trash of the user's Drive. |
move | Folder | Moves this item to the provided destination folder. |
remove | Folder | Removes the given user from the list of editors for theFolder. |
remove | Folder | Removes the given user from the list of editors for theFolder. |
remove | Folder | Removes the given user from the list of viewers and commenters for theFolder. |
remove | Folder | Removes the given user from the list of viewers and commenters for theFolder. |
revoke | Folder | Revokes the access to theFolder granted to the given user. |
revoke | Folder | Revokes the access to theFolder granted to the given user. |
search | File | Gets a collection of all files that are children of the current folder and match the given searchcriteria. |
search | Folder | Gets a collection of all folders that are children of the current folder and match the given searchcriteria. |
set | Folder | Sets the description for theFolder. |
set | Folder | Sets the name of theFolder. |
set | Folder | Changes the owner of theFolder. |
set | Folder | Changes the owner of theFolder. |
set | Folder | Sets whether theFolder requires a resource key for access when it'sshared using a link. |
set | Folder | Sets whether users with edit permissions to theFolder are allowed to sharewith other users or change the permissions. |
set | Folder | Sets which class of users can access theFolder and what permissionsthose users are granted, besides any individual users who have been explicitly given access. |
set | Folder | Sets whether theFolder is starred in the user's Drive. |
set | Folder | Sets whether theFolder is in the trash of the user's Drive. |
FolderIterator
Methods
| Method | Return type | Brief description |
|---|---|---|
get | String | Gets a token that can be used to resume this iteration at a later time. |
has | Boolean | Determines whether callingnext() will return an item. |
next() | Folder | Gets the next item in the collection of files or folders. |
Permission
Properties
| Property | Type | Description |
|---|---|---|
VIEW | Enum | Users who can access the file or folder are able only to view it or copy it. |
EDIT | Enum | Users who can access the file or folder are able to edit it. |
COMMENT | Enum | Users who can access the file or folder are able only to view it, copy it, or comment on it. |
OWNER | Enum | The user owns the file or folder. |
ORGANIZER | Enum | Users who can organize files and folders within a shared drive. |
FILE_ORGANIZER | Enum | Users who can edit, trash, and move content within a shared drive. |
NONE | Enum | The user does not have any permissions for the file or folder. |
User
Methods
| Method | Return type | Brief description |
|---|---|---|
get | String|null | Gets the domain name associated with the user's account. |
get | String|null | Gets the user's email address. |
get | String|null | Gets the user's name. |
get | String|null | Gets 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.