Google Apps Script

DocsList Service

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

// This example creates a file called 'example file'
DocsList.createFile('example file', 'example file contents');

Classes

NameBrief description
DocsListThe DocsList service contains methods to create and retrieve files and folders.
FileThis class contains methods to get information about the file and modify its contents.
FileTypeAn enumeration used to represent various Google and non-Google file types.
FilesResultHolds an array of files as well as a token used to enable pagination in methods that return a limited number of items such as DocsList.getAllFilesForPaging(number, token).
FolderA folder contains methods to create, find, and access files inside of itself.
FoldersResultHolds an array of folders as well as a token used to enable pagination in methods that return a limited number of items such as DocsList.getAllFoldersForPaging(number, token).
TokenA token object used to enable pagination in methods that return a limited number of items.

Class DocsList

Properties

PropertyTypeDescription
DEFAULT_RESULT_SIZEIntegerThe default number of items returned in functions such as getAllFiles().
FileTypeFileType
MAX_RESULT_SIZEIntegerThe maximum number of items returned in functions such as getAllFilesForPaging(number).

Methods

MethodReturn typeBrief description
createFile(blob)FileCreates a file using the data stored in this blob.
createFile(name, contents)FileCreates a file with the given name and contents in the current folder.
createFile(name, contents, mimeType)FileCreates a file with the given name and contents in the current folder with the given MIME type.
createFolder(name)FolderCreates a sub-folder with the given name in the current folder.
find(query)File[]Returns an array of all the files in the container that contain the given string.
findForPaging(query, number)FilesResultReturns the next number files maching the search query and a paging token.
findForPaging(query, number, token)FilesResultReturns the next number files maching the search query, picking up from where the token from the previous lookup left off.
getAllFiles()File[]Returns all the files in the user's drive (up to a maximum of DEFAULT_RESULT_SIZE).
getAllFilesForPaging(number)FilesResultReturns the first number files in drive (up to a maximum of MAX_RESULT_SIZE) and a paging token.
getAllFilesForPaging(number, token)FilesResultReturns the next number files in the user's drive, picking up from where the token from the previous lookup left off.
getAllFolders()Folder[]Returns all the folders in the user's drive (up to a maximum of DEFAULT_RESULT_SIZE).
getAllFoldersForPaging(number)FoldersResultReturns the first number folders in drive and a paging token.
getAllFoldersForPaging(number, token)FoldersResultReturns the next number folders in the user's drive, picking up from where the token from the previous lookup left off.
getFileById(id)FileGets the file with the given ID.
getFilesByType(type)File[]Returns all files of a given type.
getFilesByTypeForPaging(type, number)FilesResultReturns the next number files of the given type in this container and a paging token.
getFilesByTypeForPaging(type, number, token)FilesResultReturns the next number files of the given type in this container, picking up from where the token from the previous lookup left off.
getFolder(path)FolderReturns the folder at a given path.
getFolderById(id)FolderGets the folder with the given ID.
getRootFolder()FolderReturns the root folder.

Class File

Methods

MethodReturn typeBrief description
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.
addToFolder(parent)voidAdds the item to the given folder.
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.
append(contents)voidAppends the given string to the existing contents of the file.
clear()voidClears all the contents of a document that is not of a Google Docs format.
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.
getContentAsString()StringReturns the contents of any file that isn't a Google document type as a string.
getDateCreated()DateGets the date that this item was created.
getDescription()StringReturns the description of the item or null if a description doesn't exist.
getEditors()User[]Gets the list of editors for this File.
getFileType()FileTypeReturns the FileType of the file.
getId()StringReturns the document ID associated with the item.
getLastUpdated()DateGets the date that this item was last updated.
getName()StringReturns the name of the item.
getOwner()UserGets the owner of the item.
getParents()Folder[]Returns the parent folders.
getSize()IntegerReturns the amount of disk space used by the item.
getThumbnail()BlobReturns the thumbnail image associated with this item, or null if no thumbnail exists.
getUrl()StringReturns a URL to access the particular item.
getViewers()User[]Gets the list of viewers and commenters for this File.
isStarred()BooleanGets whether the item is starred.
isTrashed()BooleanChecks whether the item is trashed.
makeCopy()FileMakes a copy of the file with a default name (i.e.
makeCopy(newName)FileReturns a copy of the current file with the given name.
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.
removeFromFolder(parent)voidRemoves this object from the given folder.
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.
rename(newName)voidRename the item.
replace(contents)voidReplaces the contents of the file with the contents provided.
setDescription(description)voidUpdate's the item's description.
setStarred(starred)voidSets the item's starred status in drive.
setTrashed(trash)voidSets the trashed status of an item but does not permanently delete it.

Class FileType

Properties

PropertyTypeDescription
DOCUMENTEnum
SPREADSHEETEnum
PRESENTATIONEnum
DRAWINGEnum
FORMEnum
OTHEREnum

Class FilesResult

Methods

MethodReturn typeBrief description
getFiles()File[]Gets the files contained in this result.
getToken()TokenGets the token for this result.

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.
addToFolder(parent)voidAdds the item to the given 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 using the data stored in this blob.
createFile(name, contents)FileCreates a file with the given name and contents in the current folder.
createFile(name, contents, mimeType)FileCreates a file with the given name and contents in the current folder with the given MIME type.
createFolder(name)FolderCreates a sub-folder with the given name in the current folder.
find(query)File[]Returns an array of all the files in the container that contain the given string.
findForPaging(query, number)FilesResultReturns the next number files maching the search query and a paging token.
findForPaging(query, number, token)FilesResultReturns the next number files maching the search query, picking up from where the token from the previous lookup left off.
getDateCreated()DateGets the date that this item was created.
getDescription()StringReturns the description of the item or null if a description doesn't exist.
getEditors()User[]Gets the list of editors for this Folder.
getFiles()File[]Returns all the files in the container (up to a maximum of DocsList.DEFAULT_RESULT_SIZE).
getFilesByType(type)File[]Returns all files of a given type.
getFilesByTypeForPaging(type, number)FilesResultReturns the next number files of the given type in this container and a paging token.
getFilesByTypeForPaging(type, number, token)FilesResultReturns the next number files of the given type in this container, picking up from where the token from the previous lookup left off.
getFilesForPaging(number)FilesResultReturns the next number files in this container and a paging token.
getFilesForPaging(number, token)FilesResultReturns the next number files in this container, picking up from where the token from the previous lookup left off.
getFolders()Folder[]Returns all the folders in this container (up to a maximum of DocsList.DEFAULT_RESULT_SIZE).
getFoldersForPaging(number)FoldersResultReturns the first number of folders in this container and a paging token.
getFoldersForPaging(number, token)FoldersResultReturns the next number folders in this container, picking up from where the token from the previous lookup left off.
getId()StringReturns the document ID associated with the item.
getLastUpdated()DateGets the date that this item was last updated.
getName()StringReturns the name of the item.
getOwner()UserGets the owner of the item.
getParents()Folder[]Returns the parent folders.
getSize()IntegerReturns the amount of disk space used by the item.
getUrl()StringReturns a URL to access the particular item.
getViewers()User[]Gets the list of viewers and commenters for this Folder.
isStarred()BooleanGets whether the item is starred.
isTrashed()BooleanChecks whether the item is trashed.
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.
removeFromFolder(parent)voidRemoves this object from the given 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.
rename(newName)voidRename the item.
setDescription(description)voidUpdate's the item's description.
setStarred(starred)voidSets the item's starred status in drive.
setTrashed(trash)voidSets the trashed status of an item but does not permanently delete it.

Class FoldersResult

Methods

MethodReturn typeBrief description
getFolders()Folder[]Gets the folders contained in this result.
getToken()TokenGets the token for this result.

Class Token

Authentication required

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

Signing you in...

Google Developers needs your permission to do that.