Drive Service

Drive

This service lets scripts create, find, and modify files and folders in Google 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 the advanced Drive service .

If your script uses a standard 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's My Drive folder:
  // 
  
 Logs 
  
 the 
  
 name 
  
 of 
  
 every 
  
 file 
  
 in 
  
 the 
  
 user 
 's Drive. 
 var 
  
 files 
  
 = 
  
 DriveApp 
 . 
 getFiles 
 (); 
 while 
  
 ( 
 files 
 . 
 hasNext 
 ()) 
  
 { 
  
 var 
  
 file 
  
 = 
  
 files 
 . 
 next 
 (); 
  
 console 
 . 
 log 
 ( 
 file 
 . 
 getName 
 ()); 
 } 
 

Classes

Name Brief description
Access An enum representing classes of users who can access a file or folder, besides any individual users who have been explicitly given access.
Drive App Allows scripts to create, find, and modify files and folders in Google Drive.
File A file in Google Drive.
File Iterator An iterator that allows scripts to iterate over a potentially large collection of files.
Folder A folder in Google Drive.
Folder Iterator 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, besides any 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.

Drive App

Properties

Property Type Description
Access
Access An enum representing classes of users who can access a file or folder, besides any individual users who have been explicitly given access.
Permission
Permission An enum representing the permissions granted to users who can access a file or folder, besides any individual users who have been explicitly given access.

Methods

Method Return type Brief description
File Iterator Resumes a file iteration using a continuation token from a previous iterator.
Folder Iterator Resumes a folder iteration using a continuation token from a previous iterator.
File Creates a file in the root of the user's Drive from a given Blob of arbitrary data.
File Creates a text file in the root of the user's Drive with the given name and contents.
File Creates a file in the root of the user's Drive with the given name, contents, and MIME type.
Folder Creates a folder in the root of the user's Drive with the given name.
File Creates a shortcut to the provided Drive item ID, and returns it.
File Creates a shortcut to the provided Drive item ID and resource key, and returns it.
void Enables or disables enforceSingleParent behavior for all calls affecting item parents.
File Gets the file with the given ID.
File Gets the file with the given ID and resource key.
File Iterator Gets a collection of all files in the user's Drive.
File Iterator Gets a collection of all files in the user's Drive that have the given name.
File Iterator Gets a collection of all files in the user's Drive that have the given MIME type.
Folder Gets the folder with the given ID.
Folder Gets the folder with the given ID and resource key.
Folder Iterator Gets a collection of all folders in the user's Drive.
Folder Iterator Gets a collection of all folders in the user's Drive that have the given name.
Folder Gets the folder at the root of the user's Drive.
Integer Gets the number of bytes the user is allowed to store in Drive.
Integer Gets the number of bytes the user is currently storing in Drive.
File Iterator Gets a collection of all the files in the trash of the user's Drive.
Folder Iterator Gets a collection of all the folders in the trash of the user's Drive.
File Iterator Gets a collection of all files in the user's Drive that match the given search criteria.
Folder Iterator Gets a collection of all folders in the user's Drive that match the given search criteria.

File

Methods

Method Return type Brief description
File Add the given user to the list of commenters for the File .
File Add the given user to the list of commenters for the File .
File Add the given array of users to the list of commenters for the File .
File Adds the given user to the list of editors for the File .
File Adds the given user to the list of editors for the File .
File Adds the given array of users to the list of editors for the File .
File Adds the given user to the list of viewers for the File .
File Adds the given user to the list of viewers for the File .
File Adds the given array of users to the list of viewers for the File .
Permission Gets the permission granted to a specific user.
Permission Gets the permission granted to a specific user.
Blob Return the data inside this object as a blob converted to the specified content type.
Blob Return the data inside this object as a blob.
Date Gets the date the File was created.
String Gets the description for the File .
String Gets the URL that can be used to download the file.
User[] Gets the list of editors for this File .
String Gets the ID of the File .
Date Gets the date the File was last updated.
String Gets the MIME type of the file.
String Gets the name of the File .
User Gets the file owner.
Folder Iterator Gets a collection of folders that are immediate parents of the File .
String Gets the resource key of the File that is required to access items that have been shared using a link.
Boolean Gets whether this File is eligible to apply the security update that requires a resource key for access when it's shared using a link.
Boolean Gets whether this File requires a resource key for access when it's shared using a link.
Access Gets which class of users can access the File , besides any individual users who have been explicitly given access.
Permission Gets the permission granted to those users who can access the File , besides any individual users who have been explicitly given access.
Integer Gets the number of bytes used to store the File in Drive.
String If this is a Shortcut, returns the ID of the item it points to.
String If this is a Shortcut, returns the mime type of the item it points to.
String If the file is a shortcut, returns the resource key of the item it points to.
Blob Gets a thumbnail image for the file, or null if no thumbnail exists.
String Gets the URL that can be used to open the File in a Google App like Drive or Docs.
User[] Gets the list of viewers and commenters for this File .
Boolean Determines whether users with edit permissions to the File are allowed to share with other users or change the permissions.
Boolean Determines whether the File has been starred in the user's Drive.
Boolean Determines whether the File is in the trash of the user's Drive.
File Creates a copy of the file.
File Creates a copy of the file in the destination directory.
File Creates a copy of the file and names it with the name provided.
File Creates a copy of the file in the destination directory and names it with the name provided.
File Moves this item to the provided destination folder.
File Removes the given user from the list of commenters for the File .
File Removes the given user from the list of commenters for the File .
File Removes the given user from the list of editors for the File .
File Removes the given user from the list of editors for the File .
File Removes the given user from the list of viewers and commenters for the File .
File Removes the given user from the list of viewers and commenters for the File .
File Revokes the access to the File granted to the given user.
File Revokes the access to the File granted to the given user.
File Overwrites the content of the file with a given replacement.
File Sets the description for the File .
File Sets the name of the File .
File Changes the owner of the File .
File Changes the owner of the File .
File Sets whether the File requires a resource key for access when it's shared using a link.
File Sets whether users with edit permissions to the File are allowed to share with other users or change the permissions.
File Sets which class of users can access the File and what permissions those users are granted, besides any individual users who have been explicitly given access.
File Sets whether the File is starred in the user's Drive.
File Sets whether the File is in the trash of the user's Drive.

File Iterator

Methods

Method Return type Brief description
String Gets a token that can be used to resume this iteration at a later time.
Boolean Determines whether calling next() will return an item.
File Gets the next item in the collection of files or folders.

Folder

Methods

Method Return type Brief description
Folder Adds the given user to the list of editors for the Folder .
Folder Adds the given user to the list of editors for the Folder .
Folder Adds the given array of users to the list of editors for the Folder .
Folder Adds the given user to the list of viewers for the Folder .
Folder Adds the given user to the list of viewers for the Folder .
Folder Adds the given array of users to the list of viewers for the Folder .
File Creates a file in the current folder from a given Blob of arbitrary data.
File Creates a text file in the current folder with the given name and contents.
File Creates a file in the current folder with the given name, contents, and MIME type.
Folder Creates a folder in the current folder with the given name.
File Creates a shortcut to the provided Drive item ID, and returns it.
File Creates a shortcut to the provided Drive item ID and resource key, and returns it.
Permission Gets the permission granted to a specific user.
Permission Gets the permission granted to a specific user.
Date Gets the date the Folder was created.
String Gets the description for the Folder .
User[] Gets the list of editors for this Folder .
File Iterator Gets a collection of all files that are children of the current folder.
File Iterator Gets a collection of all files that are children of the current folder and have the given name.
File Iterator Gets a collection of all files that are children of the current folder and have the given MIME type.
Folder Iterator Gets a collection of all folders that are children of the current folder.
Folder Iterator Gets a collection of all folders that are children of the current folder and have the given name.
String Gets the ID of the Folder .
Date Gets the date the Folder was last updated.
String Gets the name of the Folder .
User Gets the owner of this Folder .
Folder Iterator Gets a collection of folders that are immediate parents of the Folder .
String Gets the resource key of the Folder that is required to access items that have been shared using a link.
Boolean Gets whether this Folder is eligible to apply the security update that requires a resource key for access when it's shared using a link.
Boolean Gets whether this Folder requires a resource key for access when it's shared using a link.
Access Gets which class of users can access the Folder , besides any individual users who have been explicitly given access.
Permission Gets the permission granted to those users who can access the Folder , besides any individual users who have been explicitly given access.
Integer Gets the number of bytes used to store the Folder in Drive.
String Gets the URL that can be used to open the Folder in a Google App like Drive or Docs.
User[] Gets the list of viewers and commenters for this Folder .
Boolean Determines whether users with edit permissions to the Folder are allowed to share with other users or change the permissions.
Boolean Determines whether the Folder has been starred in the user's Drive.
Boolean Determines whether the Folder is in the trash of the user's Drive.
Folder Moves this item to the provided destination folder.
Folder Removes the given user from the list of editors for the Folder .
Folder Removes the given user from the list of editors for the Folder .
Folder Removes the given user from the list of viewers and commenters for the Folder .
Folder Removes the given user from the list of viewers and commenters for the Folder .
Folder Revokes the access to the Folder granted to the given user.
Folder Revokes the access to the Folder granted to the given user.
File Iterator Gets a collection of all files that are children of the current folder and match the given search criteria.
Folder Iterator Gets a collection of all folders that are children of the current folder and match the given search criteria.
Folder Sets the description for the Folder .
Folder Sets the name of the Folder .
Folder Changes the owner of the Folder .
Folder Changes the owner of the Folder .
Folder Sets whether the Folder requires a resource key for access when it's shared using a link.
Folder Sets whether users with edit permissions to the Folder are allowed to share with other users or change the permissions.
Folder Sets which class of users can access the Folder and what permissions those users are granted, besides any individual users who have been explicitly given access.
Folder Sets whether the Folder is starred in the user's Drive.
Folder Sets whether the Folder is in the trash of the user's Drive.

Folder Iterator

Methods

Method Return type Brief description
String Gets a token that can be used to resume this iteration at a later time.
Boolean Determines whether calling next() will return an item.
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
String Gets the domain name associated with the user's account.
String Gets the user's email address.
String Gets the user's name.
String Gets the URL for the user's photo.
Design a Mobile Site
View Site in Mobile | Classic
Share by: