This service lets scripts create, find, and modify files and folders in Google Drive.
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:
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. |
DriveApp | Allows scripts to create, find, and modify files and folders in Google Drive. |
File | A file in Google Drive. |
FileIterator | An iterator that allows scripts to iterate over a potentially large collection of files. |
Folder | A folder in Google Drive. |
FolderIterator | 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. |
DriveApp
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 |
---|---|---|
continueFileIterator(continuationToken) | FileIterator | Resumes a file iteration using a continuation token from a previous iterator. |
continueFolderIterator(continuationToken) | FolderIterator | Resumes a folder iteration using a continuation token from a previous iterator. |
createFile(blob) | File | Creates a file in the root of the user's Drive from a given Blob of arbitrary data. |
createFile(name, content) | File | Creates a text file in the root of the user's Drive with the given name and contents. |
createFile(name, content, mimeType) | File | Creates a file in the root of the user's Drive with the given name, contents, and MIME type. |
createFolder(name) | Folder | Creates a folder in the root of the user's Drive with the given name. |
createShortcut(targetId) | File | Creates a shortcut to the provided Drive item ID, and returns it. |
createShortcutForTargetIdAndResourceKey(targetId, targetResourceKey) | File | Creates a shortcut to the provided Drive item ID and resource key, and returns it. |
enforceSingleParent(value) | void | Enables or disables enforceSingleParent behavior for all calls affecting item parents. |
getFileById(id) | File | Gets the file with the given ID. |
getFileByIdAndResourceKey(id, resourceKey) | File | Gets the file with the given ID and resource key. |
getFiles() | FileIterator | Gets a collection of all files in the user's Drive. |
getFilesByName(name) | FileIterator | Gets a collection of all files in the user's Drive that have the given name. |
getFilesByType(mimeType) | FileIterator | Gets a collection of all files in the user's Drive that have the given MIME type. |
getFolderById(id) | Folder | Gets the folder with the given ID. |
getFolderByIdAndResourceKey(id, resourceKey) | Folder | Gets the folder with the given ID and resource key. |
getFolders() | FolderIterator | Gets a collection of all folders in the user's Drive. |
getFoldersByName(name) | FolderIterator | Gets a collection of all folders in the user's Drive that have the given name. |
getRootFolder() | Folder | Gets the folder at the root of the user's Drive. |
getStorageLimit() | Integer | Gets the number of bytes the user is allowed to store in Drive. |
getStorageUsed() | Integer | Gets the number of bytes the user is currently storing in Drive. |
getTrashedFiles() | FileIterator | Gets a collection of all the files in the trash of the user's Drive. |
getTrashedFolders() | FolderIterator | Gets a collection of all the folders in the trash of the user's Drive. |
searchFiles(params) | FileIterator | Gets a collection of all files in the user's Drive that match the given search criteria. |
searchFolders(params) | FolderIterator | Gets a collection of all folders in the user's Drive that match the given search criteria. |
File
Methods
Method | Return type | Brief description |
---|---|---|
addCommenter(emailAddress) | File | Add the given user to the list of commenters for the File . |
addCommenter(user) | File | Add the given user to the list of commenters for the File . |
addCommenters(emailAddresses) | File | Add the given array of users to the list of commenters for the File . |
addEditor(emailAddress) | File | Adds the given user to the list of editors for the File . |
addEditor(user) | File | Adds the given user to the list of editors for the File . |
addEditors(emailAddresses) | File | Adds the given array of users to the list of editors for the File . |
addViewer(emailAddress) | File | Adds the given user to the list of viewers for the File . |
addViewer(user) | File | Adds the given user to the list of viewers for the File . |
addViewers(emailAddresses) | File | Adds the given array of users to the list of viewers for the File . |
getAccess(email) | Permission | Gets the permission granted to a specific user. |
getAccess(user) | Permission | Gets the permission granted to a specific user. |
getAs(contentType) | Blob | Return the data inside this object as a blob converted to the specified content type. |
getBlob() | Blob | Return the data inside this object as a blob. |
getDateCreated() | Date | Gets the date the File was created. |
getDescription() | String | Gets the description for the File . |
getDownloadUrl() | String | Gets the URL that can be used to download the file. |
getEditors() | User[] | Gets the list of editors for this File . |
getId() | String | Gets the ID of the File . |
getLastUpdated() | Date | Gets the date the File was last updated. |
getMimeType() | String | Gets the MIME type of the file. |
getName() | String | Gets the name of the File . |
getOwner() | User | Gets the file owner. |
getParents() | FolderIterator | Gets a collection of folders that are immediate parents of the File . |
getResourceKey() | String | Gets the resource key of the File that is required to access items that
have been shared using a link. |
getSecurityUpdateEligible() | 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. |
getSecurityUpdateEnabled() | Boolean | Gets whether this File requires a resource key for access when it's
shared using a link. |
getSharingAccess() | Access | Gets which class of users can access the File , besides any individual
users who have been explicitly given access. |
getSharingPermission() | Permission | Gets the permission granted to those users who can access the File ,
besides any individual users who have been explicitly given access. |
getSize() | Integer | Gets the number of bytes used to store the File in Drive. |
getTargetId() | String | If this is a Shortcut, returns the ID of the item it points to. |
getTargetMimeType() | String | If this is a Shortcut, returns the mime type of the item it points to. |
getTargetResourceKey() | String | If the file is a shortcut, returns the resource key of the item it points to. |
getThumbnail() | Blob | Gets a thumbnail image for the file, or null if no thumbnail exists. |
getUrl() | String | Gets the URL that can be used to open the File in a Google App like
Drive or Docs. |
getViewers() | User[] | Gets the list of viewers and commenters for this File . |
isShareableByEditors() | Boolean | Determines whether users with edit permissions to the File are allowed to
share with other users or change the permissions. |
isStarred() | Boolean | Determines whether the File has been starred in the user's Drive. |
isTrashed() | Boolean | Determines whether the File is in the trash of the user's Drive. |
makeCopy() | File | Creates a copy of the file. |
makeCopy(destination) | File | Creates a copy of the file in the destination directory. |
makeCopy(name) | File | Creates a copy of the file and names it with the name provided. |
makeCopy(name, destination) | File | Creates a copy of the file in the destination directory and names it with the name provided. |
moveTo(destination) | File | Moves this item to the provided destination folder. |
removeCommenter(emailAddress) | File | Removes the given user from the list of commenters for the File . |
removeCommenter(user) | File | Removes the given user from the list of commenters for the File . |
removeEditor(emailAddress) | File | Removes the given user from the list of editors for the File . |
removeEditor(user) | File | Removes the given user from the list of editors for the File . |
removeViewer(emailAddress) | File | Removes the given user from the list of viewers and commenters for the File . |
removeViewer(user) | File | Removes the given user from the list of viewers and commenters for the File . |
revokePermissions(emailAddress) | File | Revokes the access to the File granted to the given user. |
revokePermissions(user) | File | Revokes the access to the File granted to the given user. |
setContent(content) | File | Overwrites the content of the file with a given replacement. |
setDescription(description) | File | Sets the description for the File . |
setName(name) | File | Sets the name of the File . |
setOwner(emailAddress) | File | Changes the owner of the File . |
setOwner(user) | File | Changes the owner of the File . |
setSecurityUpdateEnabled(enabled) | File | Sets whether the File requires a resource key for access when it's
shared using a link. |
setShareableByEditors(shareable) | File | Sets whether users with edit permissions to the File are allowed to share
with other users or change the permissions. |
setSharing(accessType, permissionType) | 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. |
setStarred(starred) | File | Sets whether the File is starred in the user's Drive. |
setTrashed(trashed) | File | Sets whether the File is in the trash of the user's Drive. |
FileIterator
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() | File | Gets the next item in the collection of files or folders. |
Folder
Methods
Method | Return type | Brief description |
---|---|---|
addEditor(emailAddress) | Folder | Adds the given user to the list of editors for the Folder . |
addEditor(user) | Folder | Adds the given user to the list of editors for the Folder . |
addEditors(emailAddresses) | Folder | Adds the given array of users to the list of editors for the Folder . |
addViewer(emailAddress) | Folder | Adds the given user to the list of viewers for the Folder . |
addViewer(user) | Folder | Adds the given user to the list of viewers for the Folder . |
addViewers(emailAddresses) | Folder | Adds the given array of users to the list of viewers for the Folder . |
createFile(blob) | File | Creates a file in the current folder from a given Blob of arbitrary data. |
createFile(name, content) | File | Creates a text file in the current folder with the given name and contents. |
createFile(name, content, mimeType) | File | Creates a file in the current folder with the given name, contents, and MIME type. |
createFolder(name) | Folder | Creates a folder in the current folder with the given name. |
createShortcut(targetId) | File | Creates a shortcut to the provided Drive item ID, and returns it. |
createShortcutForTargetIdAndResourceKey(targetId, targetResourceKey) | File | Creates a shortcut to the provided Drive item ID and resource key, and returns it. |
getAccess(email) | Permission | Gets the permission granted to a specific user. |
getAccess(user) | Permission | Gets the permission granted to a specific user. |
getDateCreated() | Date | Gets the date the Folder was created. |
getDescription() | String | Gets the description for the Folder . |
getEditors() | User[] | Gets the list of editors for this Folder . |
getFiles() | FileIterator | Gets a collection of all files that are children of the current folder. |
getFilesByName(name) | FileIterator | Gets a collection of all files that are children of the current folder and have the given name. |
getFilesByType(mimeType) | FileIterator | Gets a collection of all files that are children of the current folder and have the given MIME type. |
getFolders() | FolderIterator | Gets a collection of all folders that are children of the current folder. |
getFoldersByName(name) | FolderIterator | Gets a collection of all folders that are children of the current folder and have the given name. |
getId() | String | Gets the ID of the Folder . |
getLastUpdated() | Date | Gets the date the Folder was last updated. |
getName() | String | Gets the name of the Folder . |
getOwner() | User | Gets the owner of this Folder . |
getParents() | FolderIterator | Gets a collection of folders that are immediate parents of the Folder . |
getResourceKey() | String | Gets the resource key of the Folder that is required to access items that
have been shared using a link. |
getSecurityUpdateEligible() | 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. |
getSecurityUpdateEnabled() | Boolean | Gets whether this Folder requires a resource key for access when it's
shared using a link. |
getSharingAccess() | Access | Gets which class of users can access the Folder , besides any individual
users who have been explicitly given access. |
getSharingPermission() | Permission | Gets the permission granted to those users who can access the Folder ,
besides any individual users who have been explicitly given access. |
getSize() | Integer | Gets the number of bytes used to store the Folder in Drive. |
getUrl() | String | Gets the URL that can be used to open the Folder in a Google App like
Drive or Docs. |
getViewers() | User[] | Gets the list of viewers and commenters for this Folder . |
isShareableByEditors() | Boolean | Determines whether users with edit permissions to the Folder are allowed to
share with other users or change the permissions. |
isStarred() | Boolean | Determines whether the Folder has been starred in the user's Drive. |
isTrashed() | Boolean | Determines whether the Folder is in the trash of the user's Drive. |
moveTo(destination) | Folder | Moves this item to the provided destination folder. |
removeEditor(emailAddress) | Folder | Removes the given user from the list of editors for the Folder . |
removeEditor(user) | Folder | Removes the given user from the list of editors for the Folder . |
removeViewer(emailAddress) | Folder | Removes the given user from the list of viewers and commenters for the Folder . |
removeViewer(user) | Folder | Removes the given user from the list of viewers and commenters for the Folder . |
revokePermissions(emailAddress) | Folder | Revokes the access to the Folder granted to the given user. |
revokePermissions(user) | Folder | Revokes the access to the Folder granted to the given user. |
searchFiles(params) | FileIterator | Gets a collection of all files that are children of the current folder and match the given search criteria. |
searchFolders(params) | FolderIterator | Gets a collection of all folders that are children of the current folder and match the given search criteria. |
setDescription(description) | Folder | Sets the description for the Folder . |
setName(name) | Folder | Sets the name of the Folder . |
setOwner(emailAddress) | Folder | Changes the owner of the Folder . |
setOwner(user) | Folder | Changes the owner of the Folder . |
setSecurityUpdateEnabled(enabled) | Folder | Sets whether the Folder requires a resource key for access when it's
shared using a link. |
setShareableByEditors(shareable) | Folder | Sets whether users with edit permissions to the Folder are allowed to share
with other users or change the permissions. |
setSharing(accessType, permissionType) | 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. |
setStarred(starred) | Folder | Sets whether the Folder is starred in the user's Drive. |
setTrashed(trashed) | Folder | Sets whether the Folder is in the trash of the user's Drive. |
FolderIterator
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. |
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 |
---|---|---|
getDomain() | String | Gets the domain name associated with the user's account. |
getEmail() | String | Gets the user's email address. |
getName() | String | Gets the user's name. |
getPhotoUrl() | String | Gets the URL for the user's photo. |