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 |
---|---|---|
DocsList.createFile(blob) | File | Creates a file using the data stored in this blob. |
DocsList.createFile(name, contents) | File | Creates a file with the given name and contents in the current folder. |
DocsList.createFile(name, contents, mimeType) | File | Creates a file with the given name and contents in the current folder with the given MIME type. |
DocsList.createFolder(name) | Folder | Creates a sub-folder with the given name in the current folder. |
DocsList.find(query) | File[] | Returns an array of all the files in the container that contain the given string. |
DocsList.find(query, start, max) | File[] | Returns a subrange of the files that result from the given query. |
DocsList.findForPaging(query, number) | FilesResult | Returns the next number files maching the search query and a paging token. |
DocsList.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. |
DocsList.getAllFiles() | File[] | Returns all the files in the user's drive (up to a maximum of
DEFAULT_RESULT_SIZE ). |
DocsList.getAllFiles(start, max) | File[] | Returns a subrange of the files in the user's drive. |
DocsList.getAllFilesForPaging(number) | FilesResult | Returns the first number files in drive (up to a maximum of
MAX_RESULT_SIZE ) and a paging token. |
DocsList.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. |
DocsList.getAllFolders() | Folder[] | Returns all the folders in the user's drive (up to a maximum of
DEFAULT_RESULT_SIZE ). |
DocsList.getAllFolders(start, max) | Folder[] | Returns the requested subrange of the folders in the user's drive. |
DocsList.getAllFoldersForPaging(number) | FoldersResult | Returns the first number folders in drive and a paging token. |
DocsList.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. |
DocsList.getFileById(id) | File | Gets the file with the given ID. |
DocsList.getFilesByType(type) | File[] | Returns all files of a given type. |
DocsList.getFilesByType(type, start, max) | File[] | Returns a subrange of the files of the given type in this container. |
DocsList.getFilesByTypeForPaging(type, number) | FilesResult | Returns the next number files of the given type in this container and a
paging token. |
DocsList.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. |
DocsList.getFolder(path) | Folder | Returns the folder at a given path. |
DocsList.getFolderById(id) | Folder | Gets the folder with the given ID. |
DocsList.getRootFolder() | Folder | Returns the root folder. |
Class File
Methods
Method | Return type | Brief description |
---|---|---|
File.addEditor(emailAddress) | File | Adds the given user to the list of editors for the File . |
File.addEditor(user) | File | Adds the given user to the list of editors for the File . |
File.addEditors(emailAddresses) | File | Adds the given array of users to the list of editors for the File . |
File.addToFolder(parent) | void | Adds the item to the given folder. |
File.addViewer(emailAddress) | File | Adds the given user to the list of viewers for the File . |
File.addViewer(user) | File | Adds the given user to the list of viewers for the File . |
File.addViewers(emailAddresses) | File | Adds the given array of users to the list of viewers for the File . |
File.append(contents) | void | Appends the given string to the existing contents of the file. |
File.clear() | void | Clears all the contents of a document that is not of a Google Docs format. |
File.getAs(contentType) | CompositeBlob | Return the data inside this object as a Blob converted to the specified content type. |
File.getBlob() | Blob | Return the data inside this object as a Blob. |
File.getContentAsString() | String | Returns the contents of any file that isn't a Google document type as a string. |
File.getDateCreated() | Date | Gets the date that this item was created. |
File.getDescription() | String | Returns the description of the item or null if a description doesn't exist. |
File.getEditors() | User[] | Gets the list of editors for this File . |
File.getFileType() | FileType | Returns the FileType of the file. |
File.getId() | String | Returns the document ID associated with the item. |
File.getLastUpdated() | Date | Gets the date that this item was last updated. |
File.getName() | String | Returns the name of the item. |
File.getOwner() | User | Gets the owner of the item. |
File.getParents() | Folder[] | Returns the parent folders. |
File.getSize() | Integer | Returns the amount of disk space used by the item. |
File.getThumbnail() | Blob | Returns the thumbnail image associated with this item, or null if
no thumbnail exists. |
File.getUrl() | String | Returns a URL to access the particular item. |
File.getViewers() | User[] | Gets the list of viewers for this File . |
File.isStarred() | Boolean | Gets whether the item is starred. |
File.isTrashed() | Boolean | Checks whether the item is trashed. |
File.makeCopy() | File | Makes a copy of the file with a default name (i.e. |
File.makeCopy(newName) | File | Returns a copy of the current file with the given name. |
File.removeEditor(emailAddress) | File | Removes the given user from the list of editors for the File . |
File.removeEditor(user) | File | Removes the given user from the list of editors for the File . |
File.removeFromFolder(parent) | void | Removes this object from the given folder. |
File.removeViewer(emailAddress) | File | Removes the given user from the list of viewers for the File . |
File.removeViewer(user) | File | Removes the given user from the list of viewers for the File . |
File.rename(newName) | void | Rename the item. |
File.replace(contents) | void | Replaces the contents of the file with the contents provided. |
File.setDescription(description) | void | Update's the item's description. |
File.setStarred(starred) | void | Sets the item's starred status in drive. |
File.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 |
---|---|---|
FilesResult.getFiles() | File[] | Gets the files contained in this result. |
FilesResult.getToken() | Token | Gets the token for this result. |
Class Folder
Methods
Method | Return type | Brief description |
---|---|---|
Folder.addEditor(emailAddress) | Folder | Adds the given user to the list of editors for the Folder . |
Folder.addEditor(user) | Folder | Adds the given user to the list of editors for the Folder . |
Folder.addEditors(emailAddresses) | Folder | Adds the given array of users to the list of editors for the Folder . |
Folder.addToFolder(parent) | void | Adds the item to the given folder. |
Folder.addViewer(emailAddress) | Folder | Adds the given user to the list of viewers for the Folder . |
Folder.addViewer(user) | Folder | Adds the given user to the list of viewers for the Folder . |
Folder.addViewers(emailAddresses) | Folder | Adds the given array of users to the list of viewers for the Folder . |
Folder.createFile(blob) | File | Creates a file using the data stored in this blob. |
Folder.createFile(name, contents) | File | Creates a file with the given name and contents in the current folder. |
Folder.createFile(name, contents, mimeType) | File | Creates a file with the given name and contents in the current folder with the given MIME type. |
Folder.createFolder(name) | Folder | Creates a sub-folder with the given name in the current folder. |
Folder.find(query) | File[] | Returns an array of all the files in the container that contain the given string. |
Folder.find(query, start, max) | File[] | Returns a subrange of the files that result from the given query. |
Folder.findForPaging(query, number) | FilesResult | Returns the next number files maching the search query and a paging token. |
Folder.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. |
Folder.getDateCreated() | Date | Gets the date that this item was created. |
Folder.getDescription() | String | Returns the description of the item or null if a description doesn't exist. |
Folder.getEditors() | User[] | Gets the list of editors for this Folder . |
Folder.getFiles() | File[] | Returns all the files in the container (up to a maximum of
DocsList.DEFAULT_RESULT_SIZE ). |
Folder.getFiles(start, max) | File[] | Returns a subrange of the files in this container. |
Folder.getFilesByType(type) | File[] | Returns all files of a given type. |
Folder.getFilesByType(type, start, max) | File[] | Returns a subrange of the files of the given type in this container. |
Folder.getFilesByTypeForPaging(type, number) | FilesResult | Returns the next number files of the given type in this container and a
paging token. |
Folder.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. |
Folder.getFilesForPaging(number) | FilesResult | Returns the next number files in this container and a paging token. |
Folder.getFilesForPaging(number, token) | FilesResult | Returns the next number files in this container, picking up
from where the token from the previous lookup left off. |
Folder.getFolders() | Folder[] | Returns all the folders in this container (up to a maximum of
DocsList.DEFAULT_RESULT_SIZE ). |
Folder.getFolders(start, max) | Folder[] | Returns a subrange of the folders in this container. |
Folder.getFoldersForPaging(number) | FoldersResult | Returns the first number of folders in this container and a paging token. |
Folder.getFoldersForPaging(number, token) | FoldersResult | Returns the next number folders in this container, picking up
from where the token from the previous lookup left off. |
Folder.getId() | String | Returns the document ID associated with the item. |
Folder.getLastUpdated() | Date | Gets the date that this item was last updated. |
Folder.getName() | String | Returns the name of the item. |
Folder.getOwner() | User | Gets the owner of the item. |
Folder.getParents() | Folder[] | Returns the parent folders. |
Folder.getSize() | Integer | Returns the amount of disk space used by the item. |
Folder.getUrl() | String | Returns a URL to access the particular item. |
Folder.getViewers() | User[] | Gets the list of viewers for this Folder . |
Folder.isStarred() | Boolean | Gets whether the item is starred. |
Folder.isTrashed() | Boolean | Checks whether the item is trashed. |
Folder.removeEditor(emailAddress) | Folder | Removes the given user from the list of editors for the Folder . |
Folder.removeEditor(user) | Folder | Removes the given user from the list of editors for the Folder . |
Folder.removeFromFolder(parent) | void | Removes this object from the given folder. |
Folder.removeViewer(emailAddress) | Folder | Removes the given user from the list of viewers for the Folder . |
Folder.removeViewer(user) | Folder | Removes the given user from the list of viewers for the Folder . |
Folder.rename(newName) | void | Rename the item. |
Folder.setDescription(description) | void | Update's the item's description. |
Folder.setStarred(starred) | void | Sets the item's starred status in drive. |
Folder.setTrashed(trash) | void | Sets the trashed status of an item but does not permanently delete it. |
Class FoldersResult
Methods
Method | Return type | Brief description |
---|---|---|
FoldersResult.getFolders() | Folder[] | Gets the folders contained in this result. |
FoldersResult.getToken() | Token | Gets the token for this result. |