Deprecated. The DocsList service was deprecated on December 11, 2014. To work with files in Google Drive, use the Drive service instead.
The DocsList service contains methods to create and retrieve files and folders.
The get*ForPaging methods allow retrieval of large sets by providing a
to paginate with.
Token
// This example creates a file called 'example file'
DocsList.createFile('example file', 'example file contents');
Deprecated properties
Property | Type | Description |
---|---|---|
DEFAULT_RESULT_SIZE | Integer | The default number of items returned in functions such as . |
FileType |
| |
MAX_RESULT_SIZE | Integer | The maximum number of items returned in functions such as . |
Deprecated methods
Method | Return type | Brief description |
---|---|---|
|
| Creates a file using the data stored in this blob. |
|
| Creates a file with the given name and contents in the current folder. |
|
| Creates a file with the given name and contents in the current folder with the given MIME type. |
|
| Creates a sub-folder with the given name in the current folder. |
|
| Returns an array of all the files in the container that contain the given string. |
|
| Returns a subrange of the files that result from the given query. |
|
| Returns the next number files maching the search query and a paging token. |
|
| Returns the next number files maching the search query,
picking up from where the token from the previous lookup left off. |
|
| Returns all the files in the user's drive (up to a maximum of
). |
|
| Returns the first number files in drive (up to a maximum of
) and a paging token. |
|
| Returns the next number files in the user's drive, picking up from
where the token from the previous lookup left off. |
|
| Returns all the folders in the user's drive (up to a maximum of
). |
|
| Returns the first number folders in drive and a paging token. |
|
| Returns the next number folders in the user's drive, picking up
from where the token from the previous lookup left off. |
|
| Gets the file with the given ID. |
|
| Returns all files of a given type. |
|
| Returns a subrange of the files of the given type in this container. |
|
| Returns all files of a given type. |
|
| Returns files matching the given type. |
|
| Returns the next number files of the given type in this container and a
paging token. |
|
| Returns the next number files of the given type in this container,
picking up from where the token from the previous lookup left off. |
|
| Returns the folder at a given path. |
|
| Gets the folder with the given ID. |
|
| Returns the root folder. |
Deprecated methods
createFile(blob)
createFile(blob)
Deprecated. This function is deprecated and should not be used in new scripts.
Creates a file using the data stored in this blob.
// Fetches the Google logo and saves it to a folder
var url = 'https://www.google.com/images/srpr/logo3w.png';
var imageBlob = UrlFetchApp.fetch(url).getBlob();
var folder = DocsList.createFolder('my folder');
folder.createFile(imageBlob);
Parameters
Name | Type | Description |
---|---|---|
blob | BlobSource | the blob to create the file from |
Return
— the newly created fileFile
createFile(name, contents)
createFile(name, contents)
Deprecated. This function is deprecated and should not be used in new scripts.
Creates a file with the given name and contents in the current folder. If the file name does not contain an extension, it defaults to plain text.
// Creates a file called 'new kitten' in the 'kittens' folder
var folder = DocsList.getFolder('kittens');
folder.createFile('new kitten', 'meow');
Parameters
Name | Type | Description |
---|---|---|
name | String | the name of the new file |
contents | String | the contents of the new file |
Return
— the newly created fileFile
createFile(name, contents, mimeType)
createFile(name, contents, mimeType)
Deprecated. This function is deprecated and should not be used in new scripts.
Creates a file with the given name and contents in the current folder with the given MIME type. If the file name does not contain an extension, it defaults to plain text.
// Creates a simple XML file in the 'kittens' folder
var folder = DocsList.getFolder('kittens');
var contents = '<kitten><name>Tiny</name><age>1</age></kitten>';
folder.createFile('kittens.xml', contents, 'application/xml');
Parameters
Name | Type | Description |
---|---|---|
name | String | the name of the new file |
contents | String | the new file contents |
mimeType | String | the mime-type of the new file |
Return
— the newly created fileFile
createFolder(name)
createFolder(name)
Deprecated. This function is deprecated and should not be used in new scripts.
Creates a sub-folder with the given name in the current folder.
// Creates a subfolder in a folder called 'cats'
var folder = DocsList.createFolder('cats');
folder.createFolder('cool cats');
Parameters
Name | Type | Description |
---|---|---|
name | String | the name of the new folder |
Return
— the newly created folderFolder
find(query)
find(query)
Deprecated. This function is deprecated and should not be used in new scripts.
Returns an array of all the files in the container that contain the given string.
// Logs the name of all the files resulting from a search for 'cool cats'
var folder = DocsList.getFolder('cats');
var coolCats = folder.find('cool cats');
for (var i in coolCats) {
Logger.log(coolCats[i].getName());
}
Parameters
Name | Type | Description |
---|---|---|
query | String | the search string |
Return
— the matching filesFile[]
find(query, start, max)
find(query, start, max)
Deprecated. This function is deprecated and should not be used in new scripts.
Returns a subrange of the files that result from the given query. If there are not enough results to fill the range, a partial range will be returned.
// Logs the name of the first 3 files resulting from a search for 'cool cats'
var folder = DocsList.getFolder('cats');
var coolCats = folder.find('cool cats', 0, 3);
for (var i in coolCats) {
Logger.log(coolCats[i].getName());
}
Parameters
Name | Type | Description |
---|---|---|
query | String | the search string |
start | Integer | the 0-indexed position to start returning results from |
max | Integer | the maximum number of objects to return |
Return
— the requested number of matching filesFile[]
findForPaging(query, number)
findForPaging(query, number)
Deprecated. This function is deprecated and should not be used in new scripts.
Returns the next number
files maching the search query and a paging token.
If the requested number of files do not exist, it returns the available
files.
// Logs the name of the first 3 files resulting from a search for 'cool cats'
var folder = DocsList.getFolder('cats');
var filesResult = folder.findForPaging('cool cats', 3);
var files = FilesResult.getFiles();
for (var i in files) {
Logger.log(files[i].getName());
}
Parameters
Name | Type | Description |
---|---|---|
query | String | the search string |
number | Integer | the number of objects to return |
Return
— the requested number of matching files and a paging tokenFilesResult
findForPaging(query, number, token)
findForPaging(query, number, token)
Deprecated. This function is deprecated and should not be used in new scripts.
Returns the next number
files maching the search query,
picking up from where the token
from the previous lookup left off.
If the requested number of files do not exist, it returns the available
files.
// Logs the first 6 file names resulting from a search but does it 3 at
// a time.
var folder = DocsList.getFolder('cats');
var filesResult = folder.findForPaging('cool cats', 3);
var files = filesResult.getFiles();
var token = filesResult.getToken();
// log the first 3 file names
for (var i in files) {
Logger.log(files[i].getName());
}
filesResult = folder.findForPaging('cool cats', 3, token); // pass in previous token
files = filesResult.getFiles();
// log the next 3 file names
for (var i in files) {
Logger.log(files[i].getName());
}
Parameters
Name | Type | Description |
---|---|---|
query | String | the search string |
number | Integer | the number of objects to return |
token |
| the token from the previous lookup |
Return
— the requested number of matching files and a paging tokenFilesResult
getAllFiles()
getAllFiles()
Deprecated. This function is deprecated and should not be used in new scripts.
Returns all the files in the user's drive (up to a maximum of
).
DEFAULT_RESULT_SIZE
// Logs the first file's name.
var file = DocsList.getAllFiles()[0];
Logger.log(file.getName());
Return
— the requested filesFile[]
getAllFilesForPaging(number)
getAllFilesForPaging(number)
Deprecated. This function is deprecated and should not be used in new scripts.
Returns the first number
files in drive (up to a maximum of
) and a paging token.
If the requested number of files do not exist, it returns the available
files.
MAX_RESULT_SIZE
// Logs the first 3 file names
var filesResult = DocsList.getAllFilesForPaging(3);
var files = filesResult.getFiles();
for (var i in files) {
Logger.log(files[i].getName());
}
Parameters
Name | Type | Description |
---|---|---|
number | Integer | the number of files to return |
Return
— the requested filesFilesResult
getAllFilesForPaging(number, token)
getAllFilesForPaging(number, token)
Deprecated. This function is deprecated and should not be used in new scripts.
Returns the next number
files in the user's drive, picking up from
where the token
from the previous lookup left off.
If the requested number of files do not exist, it returns the available
files.
// Logs the first 6 file names but does it 3 at a time.
var filesResult = DocsList.getAllFilesForPaging(3);
var files = filesResult.getFiles();
var token = filesResult.getToken();
// log the first 3 file names
for (var i in files) {
Logger.log(files[i].getName());
}
fileResult = DocsList.getAllFilesForPaging(3, token); // pass in previous token
files = filesResult.getFiles();
// log the next 3 file names
for (var i in files) {
Logger.log(files[i].getName());
}
Parameters
Name | Type | Description |
---|---|---|
number | Integer | the number of files to return |
token |
| the paging token from a previous request |
Return
— the requested filesFilesResult
getAllFolders()
getAllFolders()
Deprecated. This function is deprecated and should not be used in new scripts.
Returns all the folders in the user's drive (up to a maximum of
).
DEFAULT_RESULT_SIZE
// Logs the first folder's URL.
var folder = DocsList.getAllFolders()[0];
Logger.log(folder.getUrl());
Return
— the requested foldersFolder[]
getAllFoldersForPaging(number)
getAllFoldersForPaging(number)
Deprecated. This function is deprecated and should not be used in new scripts.
Returns the first number
folders in drive and a paging token.
If the requested number of folders do not exist, it returns the available
folders.
// Logs the first 3 folder URLs (or less if there are fewer
// than 3 folders)
var foldersResult = DocsList.getAllFoldersForPaging(3);
var folders = foldersResult.getFolders();
for (var i in folders) {
Logger.log(folders[i].getUrl());
}
Parameters
Name | Type | Description |
---|---|---|
number | Integer | the number of folders to return |
Return
— the requested folders and a paging tokenFoldersResult
getAllFoldersForPaging(number, token)
getAllFoldersForPaging(number, token)
Deprecated. This function is deprecated and should not be used in new scripts.
Returns the next number
folders in the user's drive, picking up
from where the token
from the previous lookup left off.
If the requested number of folders do not exist, it returns the available
folders.
// Logs the first 6 folder URLs but does it 3 at a time.
var foldersResult = DocsList.getAllFoldersForPaging(3);
var folders = foldersResult.getFolders();
var token = foldersResult.getToken();
// log the first 3 folder URLs
for (var i in folders) {
Logger.log(folders[i].getUrl());
}
folderResult = DocsList.getAllFoldersForPaging(3, token); // pass in previous token
folders = foldersResult.getFolders();
// log the next 3 folder URLs
for (var i in folders) {
Logger.log(folders[i].getUrl());
}
Parameters
Name | Type | Description |
---|---|---|
number | Integer | the number of folders to return |
token |
| the token from a previous request |
Return
— the requested folders and a paging tokenFoldersResult
getFileById(id)
getFileById(id)
Deprecated. This function is deprecated and should not be used in new scripts.
Gets the file with the given ID.
// Gets a file by its ID and logs its name
var file = DocsList.getFileById('1234567890abcdefghijklmnopqrstuvwxyz');
Logger.log('File name: ' + file.getName());
Parameters
Name | Type | Description |
---|---|---|
id | String | the ID of the file to be fetched |
Return
— the file with the given IDFile
getFilesByType(type)
getFilesByType(type)
Deprecated. This function is deprecated and should not be used in new scripts.
Returns all files of a given type.
See
for the list of possible file types.
FileType
// Logs the names of the first document in the 'kittens' folder
var folder = DocsList.getFolder('kittens');
var file = folder.getFilesByType(DocsList.FileType.DOCUMENT)[0];
Logger.log(file.getName());
Parameters
Name | Type | Description |
---|---|---|
type |
| the type of files to get |
Return
— the requested filesFile[]
See also
getFilesByType(type, start, max)
getFilesByType(type, start, max)
Deprecated. This function is deprecated and should not be used in new scripts.
Returns a subrange of the files of the given type in this container.
If there are not enough results to fill the range, a partial range will be
returned. See
for the list of possible file types.
FileType
// Logs the names of the first three documents in the 'kittens' folder
var folder = DocsList.getFolder('kittens');
var files = folder.getFilesByType(DocsList.FileType.DOCUMENT, 0, 3);
for (var i in files) {
Logger.log(files[i].getName());
}
Parameters
Name | Type | Description |
---|---|---|
type |
| |
start | Integer | the 0-indexed position to start returning results from |
max | Integer | the maximum number of files to return |
Return
— the requested filesFile[]
See also
getFilesByType(fileType)
getFilesByType(fileType)
Deprecated. This function is deprecated and should not be used in new scripts.
Returns all files of a given type.
Parameters
Name | Type | Description |
---|---|---|
fileType | String | the type of files to get; legal values are: "spreadsheet", "document" and "presentation" |
Return
getFilesByType(fileType, start, max)
getFilesByType(fileType, start, max)
Deprecated. This function is deprecated and should not be used in new scripts.
Returns files matching the given type. This function returns a sub-range of the results. If there are not enough results to fill the range, a partial range will be returned.
Parameters
Name | Type | Description |
---|---|---|
fileType | String | the type of files to get; legal values are: "spreadsheet", "document" and "presentation" |
start | Integer | the 0-indexed position start returning results from |
max | Integer | the maximum number of objects to return |
Return
getFilesByTypeForPaging(type, number)
getFilesByTypeForPaging(type, number)
Deprecated. This function is deprecated and should not be used in new scripts.
Returns the next number
files of the given type in this container and a
paging token.
If the requested number of files do not exist, it returns the available
files.
// Logs the first 3 document names (or less if there are fewer
// than 3 documents) from the 'kittens' folder
var folder = DocsList.getFolder('kittens');
var filesResult = folder.getFilesForPaging(DocsList.FileType.DOCUMENT, 3);
var files = FilesResult.getFiles();
for (var i in files) {
Logger.log(files[i].getName());
}
Parameters
Name | Type | Description |
---|---|---|
type |
| the type of files to get |
number | Integer | the number of files to get |
Return
— the requested files and a paging tokenFilesResult
See also
getFilesByTypeForPaging(type, number, token)
getFilesByTypeForPaging(type, number, token)
Deprecated. This function is deprecated and should not be used in new scripts.
Returns the next number
files of the given type in this container,
picking up from where the token
from the previous lookup left off.
If the requested number of files do not exist, it returns the available
files.
// Logs the first 6 document names in the 'kittens' folder but does it 3 at
// a time.
var folder = DocsList.getFolder('kittens');
var filesResult = folder.getFilesForPaging(DocsList.FileType.DOCUMENT, 3);
var files = filesResult.getFiles();
var token = filesResult.getToken();
// log the first 3 document names
for (var i in files) {
Logger.log(files[i].getName());
}
// pass in previous token
filesResult = folder.getFilesForPaging(DocsList.FileType.DOCUMENT, 3, token);
files = filesResult.getFiles();
// log the next 3 document names
for (var i in files) {
Logger.log(files[i].getName());
}
Parameters
Name | Type | Description |
---|---|---|
type |
| the type of files to return |
number | Integer | the number of files to return |
token |
| the token from the previous lookup |
Return
— the requested files and paging tokenFilesResult
getFolder(path)
getFolder(path)
Deprecated. This function is deprecated and should not be used in new scripts.
Returns the folder at a given path. Folders in a path are separated by a /. An example of a valid path is: "folder1/sub folder 2". An error occurs if the path provided is not valid.
// Gets a folder called 'kittens' and logs the number of files
// it contains.
var folder = DocsList.getFolder('kittens');
Logger.log(folder.getFiles().length);
Parameters
Name | Type | Description |
---|---|---|
path | String | the path of the folder |
Return
— the requested folder at that pathFolder
getFolderById(id)
getFolderById(id)
Deprecated. This function is deprecated and should not be used in new scripts.
Gets the folder with the given ID.
// Gets a folder by its ID and logs its name
var folder = DocsList.getFolderById('1234567890abcdefghijklmnopqrstuvwxyz');
Logger.log('Folder name: ' + folder.getName());
Parameters
Name | Type | Description |
---|---|---|
id | String | the ID of the folder to be fetched |
Return
— the folder with the given IDFolder
getRootFolder()
getRootFolder()
Deprecated. This function is deprecated and should not be used in new scripts.
Returns the root folder.
// Logs the number of items in the root folder
var folder = DocsList.getRootFolder();
Logger.log(folder.getFiles().length);
Return
— the root folderFolder