Google Apps Script

Drive Service

This service allows scripts to create, find, and modify files and folders in Google Drive.

// Log the name of every file in the user's Drive.
var files = DriveApp.getFiles();
while (files.hasNext()) {
  var file = files.next();
  Logger.log(file.getName());
}

Classes

NameBrief description
AccessAn enum representing classes of users who can access a file or folder, besides any individual users 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, besides any individual users who have been explicitly given access.
UserA user associated with a file in Google Drive.

Class 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.

Class DriveApp

Properties

PropertyTypeDescription
AccessAccessAn enum representing classes of users who can access a file or folder, besides any individual users who have been explicitly given access.
PermissionPermissionAn 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

MethodReturn typeBrief description
addFile(child)FolderAdds the given file to the root of the user's Drive.
addFolder(child)FolderAdds the given folder to the root of the user's Drive.
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 given Blob 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.
getFileById(id)FileGets the file with the given ID.
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.
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.
removeFile(child)FolderRemoves the given file from the root of the user's Drive.
removeFolder(child)FolderRemoves the given folder from the root of the user's Drive.
searchFiles(params)FileIteratorGets a collection of all files in the user's Drive that match the given search criteria.
searchFolders(params)FolderIteratorGets a collection of all folders in the user's Drive that match the given search criteria.

Class File

Methods

MethodReturn typeBrief description
addCommenter(emailAddress)FileAdd the given user to the list of commenters for the File.
addCommenter(user)FileAdd the given user to the list of commenters for the File.
addCommenters(emailAddresses)FileAdd the given array of users to the list of commenters for the File.
addEditor(emailAddress)FileAdds the given user to the list of editors for the File.
addEditor(user)FileAdds the given user to the list of editors for the File.
addEditors(emailAddresses)FileAdds the given array of users to the list of editors for the File.
addViewer(emailAddress)FileAdds the given user to the list of viewers for the File.
addViewer(user)FileAdds the given user to the list of viewers for the File.
addViewers(emailAddresses)FileAdds the given array of users to the list of viewers for the File.
getAccess(email)PermissionGets the permission granted to the given user.
getAccess(user)PermissionGets the permission granted to the given 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 the File was created.
getDescription()StringGets the description for the File.
getDownloadUrl()StringGets the URL that can be used to download the file.
getEditors()User[]Gets the list of editors for this File.
getId()StringGets the ID of the File.
getLastUpdated()DateGets the date the File was last updated.
getMimeType()StringGets the MIME type of the file.
getName()StringGets the name of the File.
getOwner()UserGets the owner of the File.
getParents()FolderIteratorGets a collection of folders that are immediate parents of the File.
getSharingAccess()AccessGets which class of users can access the File, besides any individual users who have been explicitly given access.
getSharingPermission()PermissionGets the permission granted to those users who can access the File, besides any individual users who have been explicitly given access.
getSize()IntegerGets the number of bytes used to store the File in Drive.
getThumbnail()BlobGets a thumbnail image for the file, or null if no thumbnail exists.
getUrl()StringGets 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()BooleanDetermines whether users with edit permissions to the File are allowed to share with other users or change the permissions.
isStarred()BooleanDetermines whether the File has been starred in the user's Drive.
isTrashed()BooleanDetermines whether the File 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.
removeCommenter(emailAddress)FileRemoves the given user from the list of commenters for the File.
removeCommenter(user)FileRemoves the given user from the list of commenters for the File.
removeEditor(emailAddress)FileRemoves the given user from the list of editors for the File.
removeEditor(user)FileRemoves the given user from the list of editors for the File.
removeViewer(emailAddress)FileRemoves the given user from the list of viewers and commenters for the File.
removeViewer(user)FileRemoves the given user from the list of viewers and commenters for the File.
revokePermissions(user)FileRevokes the access to the File granted to the given user.
revokePermissions(user)FileRevokes the access to the File granted to the given user.
setContent(content)FileOverwrites the content of the file with a given replacement.
setDescription(description)FileSets the description for the File.
setName(name)FileSets the name of the File.
setOwner(emailAddress)FileChanges the owner of the File.
setOwner(user)FileChanges the owner of the File.
setShareableByEditors(shareable)FileSets whether users with edit permissions to the File are allowed to share with other users or change the permissions.
setSharing(accessType, permissionType)FileSets 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)FileSets whether the File is starred in the user's Drive.
setTrashed(trashed)FileSets whether the File is in the trash of the user's Drive.

Class FileIterator

Methods

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

Class Folder

Methods

MethodReturn typeBrief description
addEditor(emailAddress)FolderAdds the given user to the list of editors for the Folder.
addEditor(user)FolderAdds the given user to the list of editors for the Folder.
addEditors(emailAddresses)FolderAdds the given array of users to the list of editors for the Folder.
addFile(child)FolderAdds the given file to the current folder.
addFolder(child)FolderAdds the given folder to the current folder.
addViewer(emailAddress)FolderAdds the given user to the list of viewers for the Folder.
addViewer(user)FolderAdds the given user to the list of viewers for the Folder.
addViewers(emailAddresses)FolderAdds the given array of users to the list of viewers for the Folder.
createFile(blob)FileCreates a file in the current folder from a given Blob 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.
getAccess(email)PermissionGets the permission granted to the given user.
getAccess(user)PermissionGets the permission granted to the given user.
getDateCreated()DateGets the date the Folder was created.
getDescription()StringGets the description for the Folder.
getEditors()User[]Gets the list of editors for this Folder.
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 the Folder.
getLastUpdated()DateGets the date the Folder was last updated.
getName()StringGets the name of the Folder.
getOwner()UserGets the owner of the Folder.
getParents()FolderIteratorGets a collection of folders that are immediate parents of the Folder.
getSharingAccess()AccessGets which class of users can access the Folder, besides any individual users who have been explicitly given access.
getSharingPermission()PermissionGets the permission granted to those users who can access the Folder, besides any individual users who have been explicitly given access.
getSize()IntegerGets the number of bytes used to store the Folder in Drive.
getUrl()StringGets 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()BooleanDetermines whether users with edit permissions to the Folder are allowed to share with other users or change the permissions.
isStarred()BooleanDetermines whether the Folder has been starred in the user's Drive.
isTrashed()BooleanDetermines whether the Folder is in the trash of the user's Drive.
removeEditor(emailAddress)FolderRemoves the given user from the list of editors for the Folder.
removeEditor(user)FolderRemoves the given user from the list of editors for the Folder.
removeFile(child)FolderRemoves the given file from the current folder.
removeFolder(child)FolderRemoves the given folder from the current folder.
removeViewer(emailAddress)FolderRemoves the given user from the list of viewers and commenters for the Folder.
removeViewer(user)FolderRemoves the given user from the list of viewers and commenters for the Folder.
revokePermissions(user)FolderRevokes the access to the Folder granted to the given user.
revokePermissions(user)FolderRevokes the access to the Folder granted to the given user.
searchFiles(params)FileIteratorGets a collection of all files that are children of the current folder and match the given search criteria.
searchFolders(params)FolderIteratorGets a collection of all folders that are children of the current folder and match the given search criteria.
setDescription(description)FolderSets the description for the Folder.
setName(name)FolderSets the name of the Folder.
setOwner(emailAddress)FolderChanges the owner of the Folder.
setOwner(user)FolderChanges the owner of the Folder.
setShareableByEditors(shareable)FolderSets whether users with edit permissions to the Folder are allowed to share with other users or change the permissions.
setSharing(accessType, permissionType)FolderSets 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)FolderSets whether the Folder is starred in the user's Drive.
setTrashed(trashed)FolderSets whether the Folder is in the trash of the user's Drive.

Class FolderIterator

Methods

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

Class 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.
NONEEnumThe user does not have any permissions for the file or folder.

Class User

Methods

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

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.