Deprecated. The DocsList service was deprecated on December 11, 2014. To work with files in Google Drive, use the Drive service instead.
This class contains methods to get information about the file and modify its contents.
// This example logs the file type of the first file
var file = DocsList.getAllFiles()[0];
Logger.log(file.getFileType());
Methods
Method | Return type | Brief description |
---|---|---|
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. |
Deprecated methods
Method | Return type | Brief description |
---|---|---|
|
| Adds the given user to the list of editors for the . |
|
| Adds the given user to the list of editors for the . |
|
| Adds the given array of users to the list of editors for the . |
| void | Adds the item to the given folder. |
|
| Adds the given user to the list of viewers for the . |
|
| Adds the given user to the list of viewers for the . |
|
| Adds the given array of users to the list of viewers for the . |
| void | Appends the given string to the existing contents of the file. |
| void | Clears all the contents of a document that is not of a Google Docs format. |
| String | Returns the contents of any file that isn't a Google document type as a string. |
| Date | Gets the date that this item was created. |
| String | Returns the description of the item or null if a description doesn't exist. |
| User[] | Gets the list of editors for this . |
|
| Returns the of the file. |
| String | Returns the document ID associated with the item. |
| Date | Gets the date that this item was last updated. |
| String | Returns the name of the item. |
| User | Gets the owner of the item. |
|
| Returns the parent folders. |
| Integer | Returns the amount of disk space used by the item. |
| Blob | Returns the thumbnail image associated with this item, or null if
no thumbnail exists. |
| String | Returns the file type. |
| String | Returns a URL to access the particular item. |
| User[] | Gets the list of viewers and commenters for this . |
| Boolean | Gets whether the item is starred. |
| Boolean | Checks whether the item is trashed. |
|
| Makes a copy of the file with a default name (i.e. |
|
| Returns a copy of the current file with the given name. |
|
| Removes the given user from the list of editors for the . |
|
| Removes the given user from the list of editors for the . |
| void | Removes this object from the given folder. |
|
| Removes the given user from the list of viewers and commenters for the . |
|
| Removes the given user from the list of viewers and commenters for the . |
| void | Rename the item. |
| void | Replaces the contents of the file with the contents provided. |
| void | Update's the item's description. |
| void | Sets the item's starred status in drive. |
| void | Sets the trashed status of an item but does not permanently delete it. |
Detailed documentation
getAs(contentType)
Return the data inside this object as a blob converted to the specified content type. This method adds the appropriate extension to the filename — for example, "myfile.pdf". However, it assumes that the part of the filename that follows the last period (if any) is an existing extension that should be replaced. Consequently, "ChristmasList.12.25.2014" will become "ChristmasList.12.25.pdf".
Parameters
Name | Type | Description |
---|---|---|
contentType | String | the MIME type to convert to. For most blobs,
'application/pdf' is the only valid option. For images in BMP, GIF, JPEG,
or PNG format, any of 'image/bmp' , 'image/gif' ,
'image/jpeg' , or 'image/png' are also valid. |
Return
Blob
— the data as a blob
Deprecated methods
addEditor(emailAddress)
addEditor(emailAddress)
Deprecated. This function is deprecated and should not be used in new scripts.
Adds the given user to the list of editors for the
. If the user was already
on the list of viewers, this method promotes the user out of the list of viewers.File
Parameters
Name | Type | Description |
---|---|---|
emailAddress | String | the email address of the user to add |
Return
addEditor(user)
addEditor(user)
Deprecated. This function is deprecated and should not be used in new scripts.
Adds the given user to the list of editors for the
. If the user was already
on the list of viewers, this method promotes the user out of the list of viewers.File
Parameters
Name | Type | Description |
---|---|---|
user | User | a representation of the user to add |
Return
addEditors(emailAddresses)
addEditors(emailAddresses)
Deprecated. This function is deprecated and should not be used in new scripts.
Adds the given array of users to the list of editors for the
. If any of the
users were already on the list of viewers, this method promotes them out of the list of
viewers.File
Parameters
Name | Type | Description |
---|---|---|
emailAddresses | String[] | an array of email addresses of the users to add |
Return
addToFolder(parent)
addToFolder(parent)
Deprecated. This function is deprecated and should not be used in new scripts.
Adds the item to the given folder.
// This example creates a new file and adds it to a folder
// Note: This can also be used on a folder to add it to another folder
var file = DocsList.createFile('my test file', 'test file contents');
var folder = DocsList.createFolder('My Test Folder');
file.addToFolder(folder);
Logger.log(file.getParents()[0].getName()); // logs 'My Test Folder'
Parameters
Name | Type | Description |
---|---|---|
parent |
| the folder to add the item to |
addViewer(emailAddress)
addViewer(emailAddress)
Deprecated. This function is deprecated and should not be used in new scripts.
Adds the given user to the list of viewers for the
. If the user was already
on the list of editors, this method has no effect.File
Parameters
Name | Type | Description |
---|---|---|
emailAddress | String | the email address of the user to add |
Return
addViewer(user)
addViewer(user)
Deprecated. This function is deprecated and should not be used in new scripts.
Adds the given user to the list of viewers for the
. If the user was already
on the list of editors, this method has no effect.File
Parameters
Name | Type | Description |
---|---|---|
user | User | a representation of the user to add |
Return
addViewers(emailAddresses)
addViewers(emailAddresses)
Deprecated. This function is deprecated and should not be used in new scripts.
Adds the given array of users to the list of viewers for the
. If any of the
users were already on the list of editors, this method has no effect for them.File
Parameters
Name | Type | Description |
---|---|---|
emailAddresses | String[] | an array of email addresses of the users to add |
Return
append(contents)
append(contents)
Deprecated. This function is deprecated and should not be used in new scripts.
Appends the given string to the existing contents of the file.
// This example creates a file called "log.txt" and appends to it.
var file = DocsList.createFile("log.txt", "My Log File");
file.append("\nFirst log entry");
Parameters
Name | Type | Description |
---|---|---|
contents | String | the string to append to the file |
clear()
clear()
Deprecated. This function is deprecated and should not be used in new scripts.
Clears all the contents of a document that is not of a Google Docs format.
It's permissible to use any document that returns
to
FileType.OTHER
.
getFileType()
// Creates a file and logs its contents before and after clear is invoked
var file = DocsList.createFile('my new file', 'sample file contents');
Logger.log('content before clear: ' + file.getContentAsString());
file.clear();
Logger.log('content after clear: ' + file.getContentAsString());
// This logs the following:
// content before clear: sample file contents
// content after clear:
getContentAsString()
getContentAsString()
Deprecated. This function is deprecated and should not be used in new scripts.
Returns the contents of any file that isn't a Google document type as a string.
// Creates a new file and logs its content
var file = DocsList.createFile('my new file', 'sample file contents');
Logger.log(file.getContentAsString()); // logs 'sample file contents'
Return
String
— the content of the file
getDateCreated()
getDateCreated()
Deprecated. This function is deprecated and should not be used in new scripts.
Gets the date that this item was created.
// This example logs the date the first file was created.
// Note: This can also be used on a folder
var file = DocsList.getAllFiles[0];
Logger.log(file.getDateCreated());
Return
Date
— the date this item was created
getDescription()
getDescription()
Deprecated. This function is deprecated and should not be used in new scripts.
Returns the description of the item or null if a description doesn't exist.
// Gets the first document's description.
// Note: This can also be used on a folder
var doc = DocsList.getFilesByType(DocsList.FileType.DOCUMENT)[0];
Logger.log(doc.getDescription());
Return
String
— the item's description
getEditors()
getEditors()
Deprecated. This function is deprecated and should not be used in new scripts.
Gets the list of editors for this
. If the user who executes the script does
not have edit access to the File
, this method throws an exception.File
Return
User[]
— an array of users with edit permission
getFileType()
getFileType()
Deprecated. This function is deprecated and should not be used in new scripts.
Returns the
of the file.
FileType
// Logs the name and file type of the first file in drive.
var file = DocsList.getAllFiles()[0];
Logger.log('Name: ' + file.getName() + ', Type: ' + file.getFileType());
Return
— the type of the fileFileType
See also
getId()
getId()
Deprecated. This function is deprecated and should not be used in new scripts.
Returns the document ID associated with the item.
// Logs the first file's document ID.
// Note: This can also be used on a folder.
var file = DocsList.getAllFiles()[0];
Logger.log(file.getId());
Return
String
— the document ID of the item
getLastUpdated()
getLastUpdated()
Deprecated. This function is deprecated and should not be used in new scripts.
Gets the date that this item was last updated.
// This example logs the date the first file was last updated.
// Note: This can also be used on a folder
var file = DocsList.getAllFiles[0];
Logger.log(file.getLastUpdated());
Return
Date
— the date this item was last updated
getName()
getName()
Deprecated. This function is deprecated and should not be used in new scripts.
Returns the name of the item.
// Logs the first file's name.
// Note: This can also be used on a folder.
var file = DocsList.getAllFiles()[0];
Logger.log(file.getName());
Return
String
— the name of the item
getOwner()
getOwner()
Deprecated. This function is deprecated and should not be used in new scripts.
Gets the owner of the item.
// This example creates a file and logs the owner's email address
// Note: This can also be used on a folder
var file = DocsList.createFile('my test file', 'test file contents');
Logger.log(file.getOwner().getEmail()); // logs your own email address
Return
User
— the owner of the item
getParents()
getParents()
Deprecated. This function is deprecated and should not be used in new scripts.
Returns the parent folders. If called on a top level item, it returns the root folder. An item can be placed in multiple folders in drive. See the drive documentation.
// This example logs the name of the parent folder of the first doc.
// Note: This can also be used on a folder to get its parent
var file = DocsList.getFilesByType(DocsList.FileType.DOCUMENT)[0];
Logger.log(file.getParents()[0].getName());
Return
— the parent folders containing the itemFolder[]
getSize()
getSize()
Deprecated. This function is deprecated and should not be used in new scripts.
Returns the amount of disk space used by the item. Note that it returns zero if called on an item that does not consume disk space, such as a Google document type file.
// This example logs the first file's size in bytes
// Note: This can also be used on a folder to get the size of its contents
var file = DocsList.getAllFiles[0];
Logger.log(file.getSize());
Return
Integer
— the item's size in bytes, or zero if the item is a Google document
type or does not consume space
getThumbnail()
getThumbnail()
Deprecated. This function is deprecated and should not be used in new scripts.
Returns the thumbnail image associated with this item, or null
if
no thumbnail exists.
// This example sends an email to the active user with a thumbnail of the
// first kitten picture in drive as an attachment.
var file = DocsList.find("kitten.jpeg")[0];
var thumbnail = file.getThumbnail();
MailApp.sendEmail(Session.getActiveUser(), 'Kitten!',
'A picture of a kitten.', { attachments: thumbnail });
Return
Blob
— the thumbnail image of this file
getType()
getType()
Deprecated. This function is deprecated and should not be used in new scripts.
Returns the file type. For the Google file types, this will be one of "spreadsheet", "document" or "presentation".
Return
String
— the file type
getUrl()
getUrl()
Deprecated. This function is deprecated and should not be used in new scripts.
Returns a URL to access the particular item.
// This example logs the first file's URL
// Note: This can also be used on a folder
var file = DocsList.getAllFiles[0];
Logger.log(file.getUrl());
Return
String
— the item's URL
getViewers()
getViewers()
Deprecated. This function is deprecated and should not be used in new scripts.
Gets the list of viewers and commenters for this
. If the user who executes
the script does not have edit access to the File
, this method throws an exception.File
Return
User[]
— an array of users with view or comment permission
isStarred()
isStarred()
Deprecated. This function is deprecated and should not be used in new scripts.
Gets whether the item is starred.
// This example creates a new file, stars it, and tests whether it is starred.
// Note: This can also be used on a folder
var file = DocsList.createFile('my test file', 'test file contents');
file.setStarred(true); // the file should be starred in drive
Logger.log(file.isStarred()); // logs true
Return
Boolean
— true if the item is starred
isTrashed()
isTrashed()
Deprecated. This function is deprecated and should not be used in new scripts.
Checks whether the item is trashed.
// This example creates a new file and then sets it trashed.
// Note: This can also be used on a folder
var file = DocsList.createFile('my test file', 'test file contents');
file.setTrashed(true); // the file should be trashed in drive
Logger.log(file.isTrashed()); // logs true
Return
Boolean
— true if the item is trashed
makeCopy()
makeCopy()
Deprecated. This function is deprecated and should not be used in new scripts.
Makes a copy of the file with a default name (i.e. 'Copy of...')
// This example makes a copy of a file called "My Document" and logs its
// name.
var file = DocsList.find("My Document")[0];
var copy = file.makeCopy();
Logger.log(copy.getName());
// There should now be a new file called "Copy of My Document".
Return
— the file copy just createdFile
makeCopy(newName)
makeCopy(newName)
Deprecated. This function is deprecated and should not be used in new scripts.
Returns a copy of the current file with the given name.
// This example copies a file called "My Document" and names it
// "My New Document".
var file = DocsList.find("My Document")[0];
var copy = file.makeCopy("My New Document");
Parameters
Name | Type | Description |
---|---|---|
newName | String | the name of the file copy |
Return
— the file copy just createdFile
removeEditor(emailAddress)
removeEditor(emailAddress)
Deprecated. This function is deprecated and should not be used in new scripts.
Removes the given user from the list of editors for the
. This method does not
block users from accessing the File
if they belong to a class of users who have
general access — for example, if the File
is shared with the user's entire domain.File
Parameters
Name | Type | Description |
---|---|---|
emailAddress | String | the email address of the user to remove |
Return
removeEditor(user)
removeEditor(user)
Deprecated. This function is deprecated and should not be used in new scripts.
Removes the given user from the list of editors for the
. This method does not
block users from accessing the File
if they belong to a class of users who have
general access — for example, if the File
is shared with the user's entire domain.File
Parameters
Name | Type | Description |
---|---|---|
user | User | a representation of the user to remove |
Return
removeFromFolder(parent)
removeFromFolder(parent)
Deprecated. This function is deprecated and should not be used in new scripts.
Removes this object from the given folder. If the item does not belong to the folder, this does nothing.
// This example creates a new file, adds it to a folder, and then removes
// it from the folder.
// Note: This can also be used on a folder to remove it from another folder
var file = DocsList.createFile('my test file', 'test file contents');
var folder = DocsList.createFolder('My Test Folder');
file.addToFolder(folder);
Logger.log(folder.getFiles().length); // logs 1
file.removeFromFolder(folder);
Logger.log(folder.getFiles().length); // logs 0
Parameters
Name | Type | Description |
---|---|---|
parent |
| the folder to remove the item from |
removeViewer(emailAddress)
removeViewer(emailAddress)
Deprecated. This function is deprecated and should not be used in new scripts.
Removes the given user from the list of viewers and commenters for the
. This
method has no effect if the user is an editor, not a viewer or commenter. This method also does
not block users from accessing the File
if they belong to a class of users who
have general access — for example, if the File
is shared with the user's entire
domain.File
Parameters
Name | Type | Description |
---|---|---|
emailAddress | String | the email address of the user to remove |
Return
removeViewer(user)
removeViewer(user)
Deprecated. This function is deprecated and should not be used in new scripts.
Removes the given user from the list of viewers and commenters for the
. This
method has no effect if the user is an editor, not a viewer. This method also does not block
users from accessing the File
if they belong to a class of users who have general
access — for example, if the File
is shared with the user's entire domain.File
Parameters
Name | Type | Description |
---|---|---|
user | User | a representation of the user to remove |
Return
rename(newName)
rename(newName)
Deprecated. This function is deprecated and should not be used in new scripts.
Rename the item.
// Creates a file called 'Old File' and renames it 'New File'.
// Note: This can also be used on a folder
var oldFile = DocsList.createFile('Old File', '');
oldFile.rename('New File');
Logger.log(oldFile.getName()); // This should log "New File"
Parameters
Name | Type | Description |
---|---|---|
newName | String | the new name of the item |
replace(contents)
replace(contents)
Deprecated. This function is deprecated and should not be used in new scripts.
Replaces the contents of the file with the contents provided.
// This example creates a file called "log.txt" and replaces its contents.
var file = DocsList.createFile("log.txt", "My Log File");
file.replace("New log content");
Parameters
Name | Type | Description |
---|---|---|
contents | String | the string with which to replace the file contents |
setDescription(description)
setDescription(description)
Deprecated. This function is deprecated and should not be used in new scripts.
Update's the item's description.
// This example sets the first document's description
// Note: This can also be used on a folder
var doc = DocsList.getFilesByType(DocsList.FileType.DOCUMENT)[0];
doc.setDescription('My First Doc');
Logger.log(doc.getDescription()); // logs 'My First Doc'
Parameters
Name | Type | Description |
---|---|---|
description | String | the item's description |
setStarred(starred)
setStarred(starred)
Deprecated. This function is deprecated and should not be used in new scripts.
Sets the item's starred status in drive.
// This example creates a new file and stars it.
// Note: This can also be used on a folder
var file = DocsList.createFile('my test file', 'test file contents');
file.setStarred(true); // the file should be starred in drive
Parameters
Name | Type | Description |
---|---|---|
starred | Boolean | stars the item if true; unstars it if false |
setTrashed(trash)
setTrashed(trash)
Deprecated. This function is deprecated and should not be used in new scripts.
Sets the trashed status of an item but does not permanently delete it.
// This example creates a new file and then sets it trashed.
// Note: This can also be used on a folder
var file = DocsList.createFile('my test file', 'test file contents');
file.setTrashed(true); // the file should be trashed in drive
Logger.log(file.isTrashed()); // logs true
Parameters
Name | Type | Description |
---|---|---|
trash | Boolean | trashes the item if true; untrashes it if false |