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
Name | Brief description |
---|---|
DocsList | The DocsList service contains methods to create and retrieve files and folders. |
File | This class contains methods to get information about the file and modify its contents. |
FileType | An enumeration used to represent various Google and non-Google file types. |
FilesResult | Holds 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) . |
Folder | A folder contains methods to create, find, and access files inside of itself. |
FoldersResult | Holds 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) . |
Token | A token object used to enable pagination in methods that return a limited number of items. |
Class DocsList
Properties
Property | Type | Description |
---|---|---|
DEFAULT_RESULT_SIZE | Integer | The default number of items returned in functions such as getAllFiles() . |
FileType | FileType | |
MAX_RESULT_SIZE | Integer | The maximum number of items returned in functions such as getAllFilesForPaging(number) . |
Methods
Method | Return type | Brief description |
---|---|---|
createFile(blob) | File | Creates a file using the data stored in this blob. |
createFile(name, contents) | File | Creates a file with the given name and contents in the current folder. |
createFile(name, contents, mimeType) | File | Creates a file with the given name and contents in the current folder with the given MIME type. |
createFolder(name) | Folder | Creates 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) | FilesResult | Returns the next number files maching the search query and a paging token. |
findForPaging(query, number, token) | FilesResult | Returns 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) | FilesResult | Returns the first number files in drive (up to a maximum of
MAX_RESULT_SIZE ) and a paging token. |
getAllFilesForPaging(number, token) | FilesResult | Returns 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) | FoldersResult | Returns the first number folders in drive and a paging token. |
getAllFoldersForPaging(number, token) | FoldersResult | Returns the next number folders in the user's drive, picking up
from where the token from the previous lookup left off. |
getFileById(id) | File | Gets the file with the given ID. |
getFilesByType(type) | File[] | Returns all files of a given type. |
getFilesByTypeForPaging(type, number) | FilesResult | Returns the next number files of the given type in this container and a
paging token. |
getFilesByTypeForPaging(type, number, token) | FilesResult | Returns 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) | Folder | Returns the folder at a given path. |
getFolderById(id) | Folder | Gets the folder with the given ID. |
getRootFolder() | Folder | Returns the root folder. |
Class File
Methods
Method | Return type | Brief description |
---|---|---|
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 . |
addToFolder(parent) | void | Adds the item to the given folder. |
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 . |
append(contents) | void | Appends the given string to the existing contents of the file. |
clear() | void | Clears all the contents of a document that is not of a Google Docs format. |
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. |
getContentAsString() | String | Returns the contents of any file that isn't a Google document type as a string. |
getDateCreated() | Date | Gets the date that this item was created. |
getDescription() | String | Returns the description of the item or null if a description doesn't exist. |
getEditors() | User[] | Gets the list of editors for this File . |
getFileType() | FileType | Returns the FileType of the file. |
getId() | String | Returns the document ID associated with the item. |
getLastUpdated() | Date | Gets the date that this item was last updated. |
getName() | String | Returns the name of the item. |
getOwner() | User | Gets the owner of the item. |
getParents() | Folder[] | Returns the parent folders. |
getSize() | Integer | Returns the amount of disk space used by the item. |
getThumbnail() | Blob | Returns the thumbnail image associated with this item, or null if
no thumbnail exists. |
getUrl() | String | Returns a URL to access the particular item. |
getViewers() | User[] | Gets the list of viewers and commenters for this File . |
isStarred() | Boolean | Gets whether the item is starred. |
isTrashed() | Boolean | Checks whether the item is trashed. |
makeCopy() | File | Makes a copy of the file with a default name (i.e. |
makeCopy(newName) | File | Returns a copy of the current file with the given name. |
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 . |
removeFromFolder(parent) | void | Removes this object from the given folder. |
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 . |
rename(newName) | void | Rename the item. |
replace(contents) | void | Replaces the contents of the file with the contents provided. |
setDescription(description) | void | Update's the item's description. |
setStarred(starred) | void | Sets the item's starred status in drive. |
setTrashed(trash) | void | Sets the trashed status of an item but does not permanently delete it. |
Class FileType
Properties
Property | Type | Description |
---|---|---|
DOCUMENT | Enum | |
SPREADSHEET | Enum | |
PRESENTATION | Enum | |
DRAWING | Enum | |
FORM | Enum | |
OTHER | Enum |
Class FilesResult
Methods
Method | Return type | Brief description |
---|---|---|
getFiles() | File[] | Gets the files contained in this result. |
getToken() | Token | Gets the token for this result. |
Class 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 . |
addToFolder(parent) | void | Adds the item to the given 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 using the data stored in this blob. |
createFile(name, contents) | File | Creates a file with the given name and contents in the current folder. |
createFile(name, contents, mimeType) | File | Creates a file with the given name and contents in the current folder with the given MIME type. |
createFolder(name) | Folder | Creates 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) | FilesResult | Returns the next number files maching the search query and a paging token. |
findForPaging(query, number, token) | FilesResult | Returns the next number files maching the search query,
picking up from where the token from the previous lookup left off. |
getDateCreated() | Date | Gets the date that this item was created. |
getDescription() | String | Returns 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) | FilesResult | Returns the next number files of the given type in this container and a
paging token. |
getFilesByTypeForPaging(type, number, token) | FilesResult | Returns 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) | FilesResult | Returns the next number files in this container and a paging token. |
getFilesForPaging(number, token) | FilesResult | Returns 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) | FoldersResult | Returns the first number of folders in this container and a paging token. |
getFoldersForPaging(number, token) | FoldersResult | Returns the next number folders in this container, picking up
from where the token from the previous lookup left off. |
getId() | String | Returns the document ID associated with the item. |
getLastUpdated() | Date | Gets the date that this item was last updated. |
getName() | String | Returns the name of the item. |
getOwner() | User | Gets the owner of the item. |
getParents() | Folder[] | Returns the parent folders. |
getSize() | Integer | Returns the amount of disk space used by the item. |
getUrl() | String | Returns a URL to access the particular item. |
getViewers() | User[] | Gets the list of viewers and commenters for this Folder . |
isStarred() | Boolean | Gets whether the item is starred. |
isTrashed() | Boolean | Checks whether the item is trashed. |
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 . |
removeFromFolder(parent) | void | Removes this object from the given 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 . |
rename(newName) | void | Rename the item. |
setDescription(description) | void | Update's the item's description. |
setStarred(starred) | void | Sets the item's starred status in drive. |
setTrashed(trash) | void | Sets the trashed status of an item but does not permanently delete it. |
Class FoldersResult
Methods
Method | Return type | Brief description |
---|---|---|
getFolders() | Folder[] | Gets the folders contained in this result. |
getToken() | Token | Gets the token for this result. |