File

A file in Google Drive. Files can be accessed or created from `https://developers.google.com/apps-script/reference/drive/drive-app`.

```javascript
// Trash every untitled spreadsheet that hasn't been updated in a week.
const files = DriveApp.getFilesByName('Untitled spreadsheet');
while (files.hasNext()) {
  const file = files.next();
  if (new Date() - file.getLastUpdated() > 7 * 24 * 60 * 60 * 1000) {
    file.setTrashed(true);
  }
}
```

### Methods

| Method | Return type | Brief description |
|---|---|---|
| `https://developers.google.com/apps-script/reference/drive/file#addCommenter(String)` | `https://developers.google.com/apps-script/reference/drive/file#` | Add the given user to the list of commenters for the `https://developers.google.com/apps-script/reference/drive/file#`. |
| `https://developers.google.com/apps-script/reference/drive/file#addCommenter(User)` | `https://developers.google.com/apps-script/reference/drive/file#` | Add the given user to the list of commenters for the `https://developers.google.com/apps-script/reference/drive/file#`. |
| `https://developers.google.com/apps-script/reference/drive/file#addCommenters(String)` | `https://developers.google.com/apps-script/reference/drive/file#` | Add the given array of users to the list of commenters for the `https://developers.google.com/apps-script/reference/drive/file#`. |
| `https://developers.google.com/apps-script/reference/drive/file#addEditor(String)` | `https://developers.google.com/apps-script/reference/drive/file#` | Adds the given user to the list of editors for the `https://developers.google.com/apps-script/reference/drive/file#`. |
| `https://developers.google.com/apps-script/reference/drive/file#addEditor(User)` | `https://developers.google.com/apps-script/reference/drive/file#` | Adds the given user to the list of editors for the `https://developers.google.com/apps-script/reference/drive/file#`. |
| `https://developers.google.com/apps-script/reference/drive/file#addEditors(String)` | `https://developers.google.com/apps-script/reference/drive/file#` | Adds the given array of users to the list of editors for the `https://developers.google.com/apps-script/reference/drive/file#`. |
| `https://developers.google.com/apps-script/reference/drive/file#addViewer(String)` | `https://developers.google.com/apps-script/reference/drive/file#` | Adds the given user to the list of viewers for the `https://developers.google.com/apps-script/reference/drive/file#`. |
| `https://developers.google.com/apps-script/reference/drive/file#addViewer(User)` | `https://developers.google.com/apps-script/reference/drive/file#` | Adds the given user to the list of viewers for the `https://developers.google.com/apps-script/reference/drive/file#`. |
| `https://developers.google.com/apps-script/reference/drive/file#addViewers(String)` | `https://developers.google.com/apps-script/reference/drive/file#` | Adds the given array of users to the list of viewers for the `https://developers.google.com/apps-script/reference/drive/file#`. |
| `https://developers.google.com/apps-script/reference/drive/file#getAccess(String)` | `https://developers.google.com/apps-script/reference/drive/permission` | Gets the permission granted to a specific user. |
| `https://developers.google.com/apps-script/reference/drive/file#getAccess(User)` | `https://developers.google.com/apps-script/reference/drive/permission` | Gets the permission granted to a specific user. |
| `https://developers.google.com/apps-script/reference/drive/file#getAs(String)` | `https://developers.google.com/apps-script/reference/base/blob.html` | Return the data inside this object as a blob converted to the specified content type. |
| `https://developers.google.com/apps-script/reference/drive/file#getBlob()` | `https://developers.google.com/apps-script/reference/base/blob.html` | Return the data inside this object as a blob. |
| `https://developers.google.com/apps-script/reference/drive/file#getDateCreated()` | `Date` | Gets the date the `https://developers.google.com/apps-script/reference/drive/file#` was created. |
| `https://developers.google.com/apps-script/reference/drive/file#getDescription()` | `String` | Gets the description for the `https://developers.google.com/apps-script/reference/drive/file#`. |
| `https://developers.google.com/apps-script/reference/drive/file#getDownloadUrl()` | `String` | Gets the URL that can be used to download the file. |
| `https://developers.google.com/apps-script/reference/drive/file#getEditors()` | `https://developers.google.com/apps-script/reference/drive/user` | Gets the list of editors for this `https://developers.google.com/apps-script/reference/drive/file#`. |
| `https://developers.google.com/apps-script/reference/drive/file#getId()` | `String` | Gets the ID of the `https://developers.google.com/apps-script/reference/drive/file#`. |
| `https://developers.google.com/apps-script/reference/drive/file#getLastUpdated()` | `Date` | Gets the date the `https://developers.google.com/apps-script/reference/drive/file#` was last updated. |
| `https://developers.google.com/apps-script/reference/drive/file#getMimeType()` | `String` | Gets the MIME type of the file. |
| `https://developers.google.com/apps-script/reference/drive/file#getName()` | `String` | Gets the name of the `https://developers.google.com/apps-script/reference/drive/file#`. |
| `https://developers.google.com/apps-script/reference/drive/file#getOwner()` | `https://developers.google.com/apps-script/reference/drive/user` | Gets the file owner. |
| `https://developers.google.com/apps-script/reference/drive/file#getParents()` | `https://developers.google.com/apps-script/reference/drive/folder-iterator` | Gets a collection of folders that are immediate parents of the `https://developers.google.com/apps-script/reference/drive/file#`. |
| `https://developers.google.com/apps-script/reference/drive/file#getResourceKey()` | `String` | Gets the resource key of the `https://developers.google.com/apps-script/reference/drive/file#` that is required to access items that have been shared using a link. |
| `https://developers.google.com/apps-script/reference/drive/file#getSecurityUpdateEligible()` | `Boolean` | Gets whether this `https://developers.google.com/apps-script/reference/drive/file#` is eligible to apply the security update that requires a resource key for access when it's shared using a link. |
| `https://developers.google.com/apps-script/reference/drive/file#getSecurityUpdateEnabled()` | `Boolean` | Gets whether this `https://developers.google.com/apps-script/reference/drive/file#` requires a resource key for access when it's shared using a link. |
| `https://developers.google.com/apps-script/reference/drive/file#getSharingAccess()` | `https://developers.google.com/apps-script/reference/drive/access` | Gets which class of users can access the `https://developers.google.com/apps-script/reference/drive/file#`, besides any individual users who have been explicitly given access. |
| `https://developers.google.com/apps-script/reference/drive/file#getSharingPermission()` | `https://developers.google.com/apps-script/reference/drive/permission` | Gets the permission granted to those users who can access the `https://developers.google.com/apps-script/reference/drive/file#`, besides any individual users who have been explicitly given access. |
| `https://developers.google.com/apps-script/reference/drive/file#getSize()` | `Integer` | Gets the number of bytes used to store the `https://developers.google.com/apps-script/reference/drive/file#` in Drive. |
| `https://developers.google.com/apps-script/reference/drive/file#getTargetId()` | `String|null` | If this is a Shortcut, returns the ID of the item it points to. |
| `https://developers.google.com/apps-script/reference/drive/file#getTargetMimeType()` | `String|null` | If this is a Shortcut, returns the mime type of the item it points to. |
| `https://developers.google.com/apps-script/reference/drive/file#getTargetResourceKey()` | `String|null` | If the file is a shortcut, returns the resource key of the item it points to. |
| `https://developers.google.com/apps-script/reference/drive/file#getThumbnail()` | `https://developers.google.com/apps-script/reference/base/blob.html|null` | Gets a thumbnail image for the file, or `null` if no thumbnail exists. |
| `https://developers.google.com/apps-script/reference/drive/file#getUrl()` | `String` | Gets the URL that can be used to open the `https://developers.google.com/apps-script/reference/drive/file#` in a Google App like Drive or Docs. |
| `https://developers.google.com/apps-script/reference/drive/file#getViewers()` | `https://developers.google.com/apps-script/reference/drive/user` | Gets the list of viewers and commenters for this `https://developers.google.com/apps-script/reference/drive/file#`. |
| `https://developers.google.com/apps-script/reference/drive/file#isShareableByEditors()` | `Boolean` | Determines whether users with edit permissions to the `https://developers.google.com/apps-script/reference/drive/file#` are allowed to share with other users or change the permissions. |
| `https://developers.google.com/apps-script/reference/drive/file#isStarred()` | `Boolean` | Determines whether the `https://developers.google.com/apps-script/reference/drive/file#` has been starred in the user's Drive. |
| `https://developers.google.com/apps-script/reference/drive/file#isTrashed()` | `Boolean` | Determines whether the `https://developers.google.com/apps-script/reference/drive/file#` is in the trash of the user's Drive. |
| `https://developers.google.com/apps-script/reference/drive/file#makeCopy()` | `https://developers.google.com/apps-script/reference/drive/file#` | Creates a copy of the file. |
| `https://developers.google.com/apps-script/reference/drive/file#makeCopy(Folder)` | `https://developers.google.com/apps-script/reference/drive/file#` | Creates a copy of the file in the destination directory. |
| `https://developers.google.com/apps-script/reference/drive/file#makeCopy(String)` | `https://developers.google.com/apps-script/reference/drive/file#` | Creates a copy of the file and names it with the name provided. |
| `https://developers.google.com/apps-script/reference/drive/file#makeCopy(String,Folder)` | `https://developers.google.com/apps-script/reference/drive/file#` | Creates a copy of the file in the destination directory and names it with the name provided. |
| `https://developers.google.com/apps-script/reference/drive/file#moveTo(Folder)` | `https://developers.google.com/apps-script/reference/drive/file#` | Moves this item to the provided destination folder. |
| `https://developers.google.com/apps-script/reference/drive/file#removeCommenter(String)` | `https://developers.google.com/apps-script/reference/drive/file#` | Removes the given user from the list of commenters for the `https://developers.google.com/apps-script/reference/drive/file#`. |
| `https://developers.google.com/apps-script/reference/drive/file#removeCommenter(User)` | `https://developers.google.com/apps-script/reference/drive/file#` | Removes the given user from the list of commenters for the `https://developers.google.com/apps-script/reference/drive/file#`. |
| `https://developers.google.com/apps-script/reference/drive/file#removeEditor(String)` | `https://developers.google.com/apps-script/reference/drive/file#` | Removes the given user from the list of editors for the `https://developers.google.com/apps-script/reference/drive/file#`. |
| `https://developers.google.com/apps-script/reference/drive/file#removeEditor(User)` | `https://developers.google.com/apps-script/reference/drive/file#` | Removes the given user from the list of editors for the `https://developers.google.com/apps-script/reference/drive/file#`. |
| `https://developers.google.com/apps-script/reference/drive/file#removeViewer(String)` | `https://developers.google.com/apps-script/reference/drive/file#` | Removes the given user from the list of viewers and commenters for the `https://developers.google.com/apps-script/reference/drive/file#`. |
| `https://developers.google.com/apps-script/reference/drive/file#removeViewer(User)` | `https://developers.google.com/apps-script/reference/drive/file#` | Removes the given user from the list of viewers and commenters for the `https://developers.google.com/apps-script/reference/drive/file#`. |
| `https://developers.google.com/apps-script/reference/drive/file#revokePermissions(String)` | `https://developers.google.com/apps-script/reference/drive/file#` | Revokes the access to the `https://developers.google.com/apps-script/reference/drive/file#` granted to the given user. |
| `https://developers.google.com/apps-script/reference/drive/file#revokePermissions(User)` | `https://developers.google.com/apps-script/reference/drive/file#` | Revokes the access to the `https://developers.google.com/apps-script/reference/drive/file#` granted to the given user. |
| `https://developers.google.com/apps-script/reference/drive/file#setContent(String)` | `https://developers.google.com/apps-script/reference/drive/file#` | Overwrites the content of the file with a given replacement. |
| `https://developers.google.com/apps-script/reference/drive/file#setDescription(String)` | `https://developers.google.com/apps-script/reference/drive/file#` | Sets the description for the `https://developers.google.com/apps-script/reference/drive/file#`. |
| `https://developers.google.com/apps-script/reference/drive/file#setName(String)` | `https://developers.google.com/apps-script/reference/drive/file#` | Sets the name of the `https://developers.google.com/apps-script/reference/drive/file#`. |
| `https://developers.google.com/apps-script/reference/drive/file#setOwner(String)` | `https://developers.google.com/apps-script/reference/drive/file#` | Changes the owner of the `https://developers.google.com/apps-script/reference/drive/file#`. |
| `https://developers.google.com/apps-script/reference/drive/file#setOwner(User)` | `https://developers.google.com/apps-script/reference/drive/file#` | Changes the owner of the `https://developers.google.com/apps-script/reference/drive/file#`. |
| `https://developers.google.com/apps-script/reference/drive/file#setSecurityUpdateEnabled(Boolean)` | `https://developers.google.com/apps-script/reference/drive/file#` | Sets whether the `https://developers.google.com/apps-script/reference/drive/file#` requires a resource key for access when it's shared using a link. |
| `https://developers.google.com/apps-script/reference/drive/file#setShareableByEditors(Boolean)` | `https://developers.google.com/apps-script/reference/drive/file#` | Sets whether users with edit permissions to the `https://developers.google.com/apps-script/reference/drive/file#` are allowed to share with other users or change the permissions. |
| `https://developers.google.com/apps-script/reference/drive/file#setSharing(Access,Permission)` | `https://developers.google.com/apps-script/reference/drive/file#` | Sets which class of users can access the `https://developers.google.com/apps-script/reference/drive/file#` and what permissions those users are granted, besides any individual users who have been explicitly given access. |
| `https://developers.google.com/apps-script/reference/drive/file#setStarred(Boolean)` | `https://developers.google.com/apps-script/reference/drive/file#` | Sets whether the `https://developers.google.com/apps-script/reference/drive/file#` is starred in the user's Drive. |
| `https://developers.google.com/apps-script/reference/drive/file#setTrashed(Boolean)` | `https://developers.google.com/apps-script/reference/drive/file#` | Sets whether the `https://developers.google.com/apps-script/reference/drive/file#` is in the trash of the user's Drive. |

## Detailed documentation

### `addCommenter(emailAddress)`

Add the given user to the list of commenters for the `https://developers.google.com/apps-script/reference/drive/file#`. If the user was
already on the list of viewers, this method promotes the user out of the list of viewers.

```javascript
const files = DriveApp.getFilesByName('Test');

// Loops through the files
while (files.hasNext()) {
  const file = files.next();
  file.addCommenter('hello@example.com');
}
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `emailAddress` | `String` | The email address of the user to add. |

#### Return


`https://developers.google.com/apps-script/reference/drive/file#` --- This `https://developers.google.com/apps-script/reference/drive/file#`, for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `addCommenter(user)`

Add the given user to the list of commenters for the `https://developers.google.com/apps-script/reference/drive/file#`. If the user was
already on the list of viewers, this method promotes the user out of the list of viewers.

```javascript
// Gets a list of all files in Google Drive with the given name.
// TODO(developer): Replace the file name with your own.
const files = DriveApp.getFilesByName('Test');

// Adds the active user as a commenter.
while (files.hasNext()) {
  const file = files.next();
  file.addCommenter(Session.getActiveUser());
}
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `user` | `https://developers.google.com/apps-script/reference/base/user.html` | A representation of the user to add. |

#### Return


`https://developers.google.com/apps-script/reference/drive/file#` --- This `https://developers.google.com/apps-script/reference/drive/file#`, for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `addCommenters(emailAddresses)`

Add the given array of users to the list of commenters for the `https://developers.google.com/apps-script/reference/drive/file#`. If any
of the users were already on the list of viewers, this method promotes them out of the list of
viewers.

```javascript
// Gets a list of all files in Google Drive with the given name.
// TODO(developer): Replace the file name with your own.
const files = DriveApp.getFilesByName('Test');

while (files.hasNext()) {
  const file = files.next();
  // TODO(developer): Replace 'cloudysanfrancisco@gmail.com' and
  // 'baklavainthebalkans@gmail.com' with the email addresses to add as
  // commenters.
  const emails = [
    'cloudysanfrancisco@gmail.com',
    'baklavainthebalkans@gmail.com',
  ];
  console.log(file.addCommenters(emails));
}
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `emailAddresses` | `String[]` | An array of email addresses of the users to add. |

#### Return


`https://developers.google.com/apps-script/reference/drive/file#` --- This `https://developers.google.com/apps-script/reference/drive/file#`, for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `addEditor(emailAddress)`

Adds the given user to the list of editors for the `https://developers.google.com/apps-script/reference/drive/file#`. If the user was already
on the list of viewers, this method promotes the user out of the list of viewers.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `emailAddress` | `String` | The email address of the user to add. |

#### Return


`https://developers.google.com/apps-script/reference/drive/file#` --- This `https://developers.google.com/apps-script/reference/drive/file#`, for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `addEditor(user)`

Adds the given user to the list of editors for the `https://developers.google.com/apps-script/reference/drive/file#`. If the user was already
on the list of viewers, this method promotes the user out of the list of viewers.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `user` | `https://developers.google.com/apps-script/reference/base/user.html` | A representation of the user to add. |

#### Return


`https://developers.google.com/apps-script/reference/drive/file#` --- This `https://developers.google.com/apps-script/reference/drive/file#`, for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `addEditors(emailAddresses)`

Adds the given array of users to the list of editors for the `https://developers.google.com/apps-script/reference/drive/file#`. If any of the
users were already on the list of viewers, this method promotes them out of the list of
viewers.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `emailAddresses` | `String[]` | An array of email addresses of the users to add. |

#### Return


`https://developers.google.com/apps-script/reference/drive/file#` --- This `https://developers.google.com/apps-script/reference/drive/file#`, for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `addViewer(emailAddress)`

Adds the given user to the list of viewers for the `https://developers.google.com/apps-script/reference/drive/file#`. If the user was already
on the list of editors, this method has no effect.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `emailAddress` | `String` | The email address of the user to add. |

#### Return


`https://developers.google.com/apps-script/reference/drive/file#` --- This `https://developers.google.com/apps-script/reference/drive/file#`, for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `addViewer(user)`

Adds the given user to the list of viewers for the `https://developers.google.com/apps-script/reference/drive/file#`. If the user was already
on the list of editors, this method has no effect.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `user` | `https://developers.google.com/apps-script/reference/base/user.html` | A representation of the user to add. |

#### Return


`https://developers.google.com/apps-script/reference/drive/file#` --- This `https://developers.google.com/apps-script/reference/drive/file#`, for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `addViewers(emailAddresses)`

Adds the given array of users to the list of viewers for the `https://developers.google.com/apps-script/reference/drive/file#`. If any of the
users were already on the list of editors, this method has no effect for them.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `emailAddresses` | `String[]` | An array of email addresses of the users to add. |

#### Return


`https://developers.google.com/apps-script/reference/drive/file#` --- This `https://developers.google.com/apps-script/reference/drive/file#`, for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `getAccess(email)`

Gets the permission granted to a specific user. The method doesn't support returning
permissions for a Google Group or permissions inherited through Google Groups.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `email` | `String` | The email address of the user whose permissions should be checked. Google Groups aren't supported. |

#### Return


`https://developers.google.com/apps-script/reference/drive/permission` --- The permissions granted to the user.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive.readonly`
- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `getAccess(user)`

Gets the permission granted to a specific user. The method doesn't support returning
permissions for a Google Group or permissions inherited through Google Groups.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `user` | `https://developers.google.com/apps-script/reference/base/user.html` | A representation of the user whose permissions should be checked. |

#### Return


`https://developers.google.com/apps-script/reference/drive/permission` --- The permissions granted to the user.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive.readonly`
- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `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, "ShoppingList.12.25.2014" becomes
"ShoppingList.12.25.pdf".

To view the daily quotas for conversions, see [Quotas for Google
Services](https://developers.google.com/apps-script/guides/services/quotas). Newly created Google Workspace domains might be temporarily subject to stricter
quotas.

#### 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. For a Google Docs document, `'text/markdown'` is also valid. |

#### Return


`https://developers.google.com/apps-script/reference/base/blob.html` --- The data as a blob.

*** ** * ** ***

### `getBlob()`

Return the data inside this object as a blob.

#### Return


`https://developers.google.com/apps-script/reference/base/blob.html` --- The data as a blob.

*** ** * ** ***

### `getDateCreated()`

Gets the date the `https://developers.google.com/apps-script/reference/drive/file#` was created.

#### Return


`Date` --- the date the `https://developers.google.com/apps-script/reference/drive/file#` was created

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive.readonly`
- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `getDescription()`

Gets the description for the `https://developers.google.com/apps-script/reference/drive/file#`.

#### Return


`String` --- the description for the `https://developers.google.com/apps-script/reference/drive/file#`

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive.readonly`
- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `getDownloadUrl()`

Gets the URL that can be used to download the file. Only users with permission to open the file
in Google Drive can access the URL. You can use this URL in a browser to download the file, but
you can't use to fetch the file with `https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app.html`. If you want the contents of the
file in the script, use `https://developers.google.com/apps-script/reference/drive/file#getBlob()`.

```javascript
// Gets a list of all files in Google Drive with the given name.
// TODO(developer): Replace the file name with your own.
const files = DriveApp.getFilesByName('Test');

// Loops through the files and logs the download URLs to the console.
while (files.hasNext()) {
  const file = files.next();
  console.log(file.getDownloadUrl());
}
```

#### Return


`String` --- The URL that can be used to download the file.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive.readonly`
- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `getEditors()`

Gets the list of editors for this `https://developers.google.com/apps-script/reference/drive/file#`. If the user who executes the script
does not have edit access to the `https://developers.google.com/apps-script/reference/drive/file#`, this method returns an empty array.

```javascript
// Gets a list of all files in Google Drive with the given name.
// TODO(developer): Replace the file name with your own.
const files = DriveApp.getFilesByName('Test');

// Loops through the files.
while (files.hasNext()) {
  const file = files.next();

  // Adds the email addresses in the array as editors of each file.
  // TODO(developer): Replace 'cloudysanfrancisco@gmail.com'
  // and 'baklavainthebalkans@gmail.com' with valid email addresses.
  file.addEditors([
    'cloudysanfrancisco@gmail.com',
    'baklavainthebalkans@gmail.com',
  ]);

  // Gets a list of the file editors.
  const editors = file.getEditors();

  // For each file, logs the editors' email addresses to the console.
  for (const editor of editors) {
    console.log(editor.getEmail());
  }
}
```

#### Return


`https://developers.google.com/apps-script/reference/drive/user` --- If the user has edit access for this `https://developers.google.com/apps-script/reference/drive/file#`, returns the list of
editors. If the user doesn't have edit access, returns an empty array.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive.readonly`
- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `getId()`

Gets the ID of the `https://developers.google.com/apps-script/reference/drive/file#`.

#### Return


`String` --- the ID of the `https://developers.google.com/apps-script/reference/drive/file#`

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive.readonly`
- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `getLastUpdated()`

Gets the date the `https://developers.google.com/apps-script/reference/drive/file#` was last updated.

#### Return


`Date` --- the date the `https://developers.google.com/apps-script/reference/drive/file#` was last updated

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive.readonly`
- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `getMimeType()`

Gets the MIME type of the file.

```javascript
// Gets a list of all files in Google Drive with the given name.
// TODO(developer): Replace the file name with your own.
const files = DriveApp.getFilesByName('Test');

// Loops through the files and logs the MIME type to the console.
while (files.hasNext()) {
  const file = files.next();
  console.log(file.getMimeType());
}
```

#### Return


`String` --- The MIME type of the file.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive.readonly`
- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `getName()`

Gets the name of the `https://developers.google.com/apps-script/reference/drive/file#`.

#### Return


`String` --- the name of the `https://developers.google.com/apps-script/reference/drive/file#`

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive.readonly`
- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `getOwner()`

Gets the file owner.

```javascript
// Gets a list of all files in Google Drive with the given name.
// TODO(developer): Replace the file name with your own.
const files = DriveApp.getFilesByName('Test');

// Loops through the files and logs the names of the file owners to the console.
while (files.hasNext()) {
  const file = files.next();
  console.log(file.getOwner().getName());
}
```

#### Return


`https://developers.google.com/apps-script/reference/drive/user` --- The file owner.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive.readonly`
- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `getParents()`

Gets a collection of folders that are immediate parents of the `https://developers.google.com/apps-script/reference/drive/file#`.

#### Return


`https://developers.google.com/apps-script/reference/drive/folder-iterator` --- a collection of folders that are immediate parents of the `https://developers.google.com/apps-script/reference/drive/file#`

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive.readonly`
- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `getResourceKey()`

Gets the resource key of the `https://developers.google.com/apps-script/reference/drive/file#` that is required to access items that
have been shared using a link.

#### Return


`String` --- The resource key of the `https://developers.google.com/apps-script/reference/drive/file#`.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive.readonly`
- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `getSecurityUpdateEligible()`

Gets whether this `https://developers.google.com/apps-script/reference/drive/file#` is eligible to apply the security update that
requires a resource key for access when it's shared using a link.

Drive requires a resource key to access some files or folders that have been shared using a
link. This change is part of a security update. The update is turned on by default for eligible
files and folders. To turn the resource key requirement on or off for eligible files, use
`setSecurityUpdateEnabled`.

Learn more about the [Security update for Google Drive](https://support.google.com/a/answer/10685032).

#### Return


`Boolean` --- Whether the resource key requirement can be applied for the `https://developers.google.com/apps-script/reference/drive/file#`.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive.readonly`
- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `getSecurityUpdateEnabled()`

Gets whether this `https://developers.google.com/apps-script/reference/drive/file#` requires a resource key for access when it's
shared using a link. This requirement is turned on by default for eligible files and folders.
To turn the resource key requirement on or off for eligible files, use `
setSecurityUpdateEnabled`.

Learn more about the [Security update for Google Drive](https://support.google.com/a/answer/10685032).

#### Return


`Boolean` --- Whether the resource key requirement is enabled for this `https://developers.google.com/apps-script/reference/drive/file#`.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive.readonly`
- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `getSharingAccess()`

Gets which class of users can access the `https://developers.google.com/apps-script/reference/drive/file#`, besides any individual
users who have been explicitly given access.

#### Return


`https://developers.google.com/apps-script/reference/drive/access` --- which class of users can access the `https://developers.google.com/apps-script/reference/drive/file#`

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive.readonly`
- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `getSharingPermission()`

Gets the permission granted to those users who can access the `https://developers.google.com/apps-script/reference/drive/file#`,
besides any individual users who have been explicitly given access.

#### Return


`https://developers.google.com/apps-script/reference/drive/permission` --- the permissions granted to users who can access the `https://developers.google.com/apps-script/reference/drive/file#`

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive.readonly`
- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `getSize()`

Gets the number of bytes used to store the `https://developers.google.com/apps-script/reference/drive/file#` in Drive. Note that
Google Workspace application files do not count toward Drive storage limits and thus return
`0` bytes.

#### Return


`Integer` --- the number of bytes used to store the `https://developers.google.com/apps-script/reference/drive/file#` in Drive

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive.readonly`
- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `getTargetId()`

If this is a Shortcut, returns the ID of the item it points to.

Otherwise it returns `null`.

```javascript
// The ID of the file for which to make a shortcut and the ID of
// the folder to which you want to add the shortcut.
// TODO(developer): Replace the file and folder IDs with your IDs.
const fileId = 'abc123456';
const folderId = 'xyz987654';

// Gets the folder to add the shortcut to.
const folder = DriveApp.getFolderById(folderId);

// Creates a shortcut of the file and moves it to the specified folder.
const shortcut = DriveApp.createShortcut(fileId).moveTo(folder);

// Logs the target ID of the shortcut.
console.log(`${shortcut.getName()}=${shortcut.getTargetId()}`);
```

#### Return


`String|null` --- The target item ID, or `null` if the file is not a shortcut.

*** ** * ** ***

### `getTargetMimeType()`

If this is a Shortcut, returns the mime type of the item it points to.

Otherwise it returns `null`.

```javascript
// The ID of the file for which to make a shortcut and the ID of
// the folder to which you want to add the shortcut.
// TODO(developer): Replace the file and folder IDs with your IDs.
const fileId = 'abc123456';
const folderId = 'xyz987654';

// Gets the folder to add the shortcut to.
const folder = DriveApp.getFolderById(folderId);

// Creates a shortcut of the file and moves it to the specified folder.
const shortcut = DriveApp.createShortcut(fileId).moveTo(folder);

// Logs the MIME type of the file that the shortcut points to.
console.log(`MIME type of the shortcut: ${shortcut.getTargetMimeType()}`);
```

#### Return


`String|null` --- The target item mime type or `null` if the file is not a shortcut.

*** ** * ** ***

### `getTargetResourceKey()`

If the file is a shortcut, returns the resource key of the item it points to. A resource key is
an additional parameter that you need to pass to access files that have been shared using a
link.

If the file isn't a shortcut, it returns `null`.

```javascript
//  Gets a file by its ID.
//  TODO(developer): Replace 'abc123456' with your file ID.
const file = DriveApp.getFileById('abc123456');

// If the file is a shortcut, returns the resource key of the file that it
// points to.
console.log(file.getTargetResourceKey());
```

#### Return


`String|null` --- The target item's resource key or `null` if the file is not a shortcut.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive.readonly`
- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `getThumbnail()`

Gets a thumbnail image for the file, or `null` if no thumbnail exists.

```javascript
// Gets a list of all files in Google Drive with the given name.
// TODO(developer): Replace the file name with your own.
const files = DriveApp.getFilesByName('Test');

// Loops through the files.
while (files.hasNext()) {
  const file = files.next();

  // Logs the thumbnail image for each file to the console as a blob,
  // or null if no thumbnail exists.
  console.log(file.getThumbnail());
}
```

#### Return


`https://developers.google.com/apps-script/reference/base/blob.html|null` --- The thumbnail image for the file.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive.readonly`
- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `getUrl()`

Gets the URL that can be used to open the `https://developers.google.com/apps-script/reference/drive/file#` in a Google App like
Drive or Docs.

#### Return


`String` --- the URL that can be used to view this `https://developers.google.com/apps-script/reference/drive/file#` in a Google App like
Drive or Docs

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive.readonly`
- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `getViewers()`

Gets the list of viewers and commenters for this `https://developers.google.com/apps-script/reference/drive/file#`. If the user who
executes the script does not have edit access to the `https://developers.google.com/apps-script/reference/drive/file#`, this method
returns an empty array.

```javascript
// Gets a list of all files in Google Drive with the given name.
// TODO(developer): Replace the file name with your own.
const files = DriveApp.getFilesByName('Test');

// Loops through the files.
while (files.hasNext()) {
  const file = files.next();

  // For each file, logs the viewers' email addresses to the console.
  const viewers = file.getViewers();
  for (const viewer of viewers) {
    console.log(viewer.getEmail());
  }
}
```

#### Return


`https://developers.google.com/apps-script/reference/drive/user` --- If the user has edit access for this `https://developers.google.com/apps-script/reference/drive/file#`, returns the list of
viewers and commenters. If the user doesn't have edit access, returns an empty array.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive.readonly`
- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `isShareableByEditors()`

Determines whether users with edit permissions to the `https://developers.google.com/apps-script/reference/drive/file#` are allowed to
share with other users or change the permissions.

#### Return


`Boolean` --- `true` if users with edit permissions are allowed to share with other users or
change the permissions; `false` if not.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive.readonly`
- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `isStarred()`

Determines whether the `https://developers.google.com/apps-script/reference/drive/file#` has been starred in the user's Drive.

#### Return


`Boolean` --- `true` if the `https://developers.google.com/apps-script/reference/drive/file#` is starred in the user's Drive; `false` if not

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive.readonly`
- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `isTrashed()`

Determines whether the `https://developers.google.com/apps-script/reference/drive/file#` is in the trash of the user's Drive.

#### Return


`Boolean` --- `true` if the `https://developers.google.com/apps-script/reference/drive/file#` is in the trash of the user's Drive;
`false` if not

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive.readonly`
- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `makeCopy()`

Creates a copy of the file.

```javascript
// Gets a list of all files in Google Drive with the given name.
// TODO(developer): Replace the file name with your own.
const files = DriveApp.getFilesByName('Test');

// Loops through the files.
while (files.hasNext()) {
  const file = files.next();

  // Creates a copy of each file and logs the file name to the console.
  console.log(file.makeCopy().getName());
}
```

#### Return


`https://developers.google.com/apps-script/reference/drive/file#` --- The new copy.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `makeCopy(destination)`

Creates a copy of the file in the destination directory.

```javascript
// Gets a list of all files in Google Drive with the given name.
// TODO(developer): Replace the file name with your own.
const files = DriveApp.getFilesByName('Test');

// Loops through the files.
while (files.hasNext()) {
  const file = files.next();

  // Creates a copy of each file and adds it to the specified folder.
  // TODO(developer): Replace the folder ID with your own.
  const destination = DriveApp.getFolderById('123456abcxyz');
  const copiedFile = file.makeCopy(destination);

  // Logs the file names to the console.
  console.log(copiedFile.getName());
}
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `destination` | `https://developers.google.com/apps-script/reference/drive/folder` | The directory to copy the file into. |

#### Return


`https://developers.google.com/apps-script/reference/drive/file#` --- The new copy.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `makeCopy(name)`

Creates a copy of the file and names it with the name provided.

```javascript
// Gets a list of all files in Google Drive with the given name.
// TODO(developer): Replace the file name with your own.
const files = DriveApp.getFilesByName('Test');

// Loops through the files.
while (files.hasNext()) {
  const file = files.next();

  // Creates a copy of each file and sets the name to 'Test-Copy.'
  const filename = file.makeCopy('Test-Copy');

  // Logs the copied file's name to the console.
  console.log(filename.getName());
}
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `name` | `String` | The filename that should be applied to the new copy. |

#### Return


`https://developers.google.com/apps-script/reference/drive/file#` --- The new copy.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `makeCopy(name, destination)`

Creates a copy of the file in the destination directory and names it with the name provided.

```javascript
// Gets a list of all files in Google Drive with the given name.
// TODO(developer): Replace the file name with your own.
const files = DriveApp.getFilesByName('Test');

// Loops through the files.
while (files.hasNext()) {
  const file = files.next();

  // Creates a copy of each file, sets the file name, and adds the copied file
  // to the specified folder.
  // TODO(developer): Replace the folder ID with your own.
  const destination = DriveApp.getFolderById('123456abcxyz');
  const copiedFile = file.makeCopy('Test-Copy', destination);

  // Logs the file names to the console.
  console.log(copiedFile.getName());
}
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `name` | `String` | The filename that should be applied to the new copy. |
| `destination` | `https://developers.google.com/apps-script/reference/drive/folder` | The directory to copy the file into. |

#### Return


`https://developers.google.com/apps-script/reference/drive/file#` --- The new copy.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `moveTo(destination)`

Moves this item to the provided destination folder.

The current user must be the owner of the file or have at least edit access to the item's
current parent folder in order to move the item to the destination folder.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `destination` | `https://developers.google.com/apps-script/reference/drive/folder` | The folder that becomes the new parent. |

#### Return


`https://developers.google.com/apps-script/reference/drive/file#` --- This `https://developers.google.com/apps-script/reference/drive/file#`, for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `removeCommenter(emailAddress)`

Removes the given user from the list of commenters for the `https://developers.google.com/apps-script/reference/drive/file#`. This method
does not block users from access the `https://developers.google.com/apps-script/reference/drive/file#` if they belong to a class of users
who have general access --- for example, if the `https://developers.google.com/apps-script/reference/drive/file#` is shared with the user's
entire domain.

```javascript
// Gets a list of all files in Google Drive with the given name.
// TODO(developer): Replace the file name with your own.
const files = DriveApp.getFilesByName('Test');

// Loops through the files.
while (files.hasNext()) {
  const file = files.next();

  // Removes the given user from the list of commenters for each file.
  // TODO(developer): Replace the email with the email of the user you want to
  // remove.
  file.removeCommenter('cloudysanfrancisco@gmail.com');
}
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `emailAddress` | `String` | The email address of the user to remove. |

#### Return


`https://developers.google.com/apps-script/reference/drive/file#` --- This `https://developers.google.com/apps-script/reference/drive/file#`, for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `removeCommenter(user)`

Removes the given user from the list of commenters for the `https://developers.google.com/apps-script/reference/drive/file#`. This method
does not block users from access the `https://developers.google.com/apps-script/reference/drive/file#` if they belong to a class of users
who have general access --- for example, if the `https://developers.google.com/apps-script/reference/drive/file#` is shared with the user's
entire domain.

```javascript
// Gets a list of all files in Google Drive with the given name.
// TODO(developer): Replace the file name with your own.
const files = DriveApp.getFilesByName('Test');

// Loops through the files.
while (files.hasNext()) {
  const file = files.next();

  // Removes the given user from the list of commenters for each file.
  console.log(file.removeCommenter(Session.getActiveUser()));
}
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `user` | `https://developers.google.com/apps-script/reference/base/user.html` | A representation of the user to remove. |

#### Return


`https://developers.google.com/apps-script/reference/drive/file#` --- This `https://developers.google.com/apps-script/reference/drive/file#`, for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `removeEditor(emailAddress)`

Removes the given user from the list of editors for the `https://developers.google.com/apps-script/reference/drive/file#`. This method doesn't
block users from accessing the `https://developers.google.com/apps-script/reference/drive/file#` if they belong to a class of users who have
general access---for example, if the `https://developers.google.com/apps-script/reference/drive/file#` is shared with the user's entire
domain, or if the `https://developers.google.com/apps-script/reference/drive/file#` is in a shared drive that the user can access.

For Drive files, this also removes the user from the list of viewers.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `emailAddress` | `String` | The email address of the user to remove. |

#### Return


`https://developers.google.com/apps-script/reference/drive/file#` --- This `https://developers.google.com/apps-script/reference/drive/file#`, for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `removeEditor(user)`

Removes the given user from the list of editors for the `https://developers.google.com/apps-script/reference/drive/file#`. This method doesn't
block users from accessing the `https://developers.google.com/apps-script/reference/drive/file#` if they belong to a class of users who have
general access---for example, if the `https://developers.google.com/apps-script/reference/drive/file#` is shared with the user's entire
domain, or if the `https://developers.google.com/apps-script/reference/drive/file#` is in a shared drive that the user can access.

For Drive files, this also removes the user from the list of viewers.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `user` | `https://developers.google.com/apps-script/reference/base/user.html` | A representation of the user to remove. |

#### Return


`https://developers.google.com/apps-script/reference/drive/file#` --- This `https://developers.google.com/apps-script/reference/drive/file#`, for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `removeViewer(emailAddress)`

Removes the given user from the list of viewers and commenters for the `https://developers.google.com/apps-script/reference/drive/file#`. This
method has no effect if the user is an editor, not a viewer or commenter. This method also
doesn't block users from accessing the `https://developers.google.com/apps-script/reference/drive/file#` if they belong to a class of users who
have general access---for example, if the `https://developers.google.com/apps-script/reference/drive/file#` is shared with the user's
entire domain, or if the `https://developers.google.com/apps-script/reference/drive/file#` is in a shared drive that the user can access.

For Drive files, this also removes the user from the list of editors.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `emailAddress` | `String` | The email address of the user to remove. |

#### Return


`https://developers.google.com/apps-script/reference/drive/file#` --- This `https://developers.google.com/apps-script/reference/drive/file#` for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `removeViewer(user)`

Removes the given user from the list of viewers and commenters for the `https://developers.google.com/apps-script/reference/drive/file#`. This
method has no effect if the user is an editor, not a viewer. This method also doesn't block
users from accessing the `https://developers.google.com/apps-script/reference/drive/file#` if they belong to a class of users who have general
access---for example, if the `https://developers.google.com/apps-script/reference/drive/file#` is shared with the user's entire domain, or
if the `https://developers.google.com/apps-script/reference/drive/file#` is in a shared drive that the user can access.

For Drive files, this also removes the user from the list of editors.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `user` | `https://developers.google.com/apps-script/reference/base/user.html` | A representation of the user to remove. |

#### Return


`https://developers.google.com/apps-script/reference/drive/file#` --- This `https://developers.google.com/apps-script/reference/drive/file#` for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `revokePermissions(emailAddress)`

Revokes the access to the `https://developers.google.com/apps-script/reference/drive/file#` granted to the given user. This method doesn't
block users from accessing the `https://developers.google.com/apps-script/reference/drive/file#` if they belong to a class of users who
have general access --- for example, if the `https://developers.google.com/apps-script/reference/drive/file#` is shared with the user's
entire domain.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `emailAddress` | `String` | The email address of the user whose access should be revoked. |

#### Return


`https://developers.google.com/apps-script/reference/drive/file#` --- This `https://developers.google.com/apps-script/reference/drive/file#`, for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `revokePermissions(user)`

Revokes the access to the `https://developers.google.com/apps-script/reference/drive/file#` granted to the given user. This method doesn't
block users from accessing the `https://developers.google.com/apps-script/reference/drive/file#` if they belong to a class of users who
have general access --- for example, if the `https://developers.google.com/apps-script/reference/drive/file#` is shared with the user's
entire domain.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `user` | `https://developers.google.com/apps-script/reference/base/user.html` | A representation of the user whose access should be revoked. |

#### Return


`https://developers.google.com/apps-script/reference/drive/file#` --- This `https://developers.google.com/apps-script/reference/drive/file#`, for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `setContent(content)`

Overwrites the content of the file with a given replacement. Throws an exception if `content` is larger than 10MB.


> [!WARNING]
> Beware: this change is irreversible.

<br />

```javascript
// Creates a text file with the content 'Hello, world!'
const file = DriveApp.createFile('New Text File', 'Hello, world!');

// Logs the content of the text file to the console.
console.log(file.getBlob().getDataAsString());

// Updates the content of the text file to 'Updated text!'
file.setContent('Updated text!');

// Logs content of the text file to the console.
console.log(file.getBlob().getDataAsString());
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `content` | `String` | The new content for the file. |

#### Return


`https://developers.google.com/apps-script/reference/drive/file#` --- This `https://developers.google.com/apps-script/reference/drive/file#`, for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `setDescription(description)`

Sets the description for the `https://developers.google.com/apps-script/reference/drive/file#`.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `description` | `String` | the new description for the `https://developers.google.com/apps-script/reference/drive/file#` |

#### Return


`https://developers.google.com/apps-script/reference/drive/file#` --- this `https://developers.google.com/apps-script/reference/drive/file#`, for chaining

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `setName(name)`

Sets the name of the `https://developers.google.com/apps-script/reference/drive/file#`.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `name` | `String` | the new name of the `https://developers.google.com/apps-script/reference/drive/file#` |

#### Return


`https://developers.google.com/apps-script/reference/drive/file#` --- this `https://developers.google.com/apps-script/reference/drive/file#`, for chaining

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `setOwner(emailAddress)`

Changes the owner of the `https://developers.google.com/apps-script/reference/drive/file#`. This method also gives the previous owner
explicit edit access to the `https://developers.google.com/apps-script/reference/drive/file#`.

Drive does not support changing the ownership for items which are owned by gmail.com
accounts; it's supported for Workspace accounts.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `emailAddress` | `String` | The email address of the user who should become the new owner. |

#### Return


`https://developers.google.com/apps-script/reference/drive/file#` --- This `https://developers.google.com/apps-script/reference/drive/file#`, for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `setOwner(user)`

Changes the owner of the `https://developers.google.com/apps-script/reference/drive/file#`. This method also gives the previous owner
explicit edit access to the `https://developers.google.com/apps-script/reference/drive/file#`.

Drive does not support changing the ownership for items which are owned by gmail.com
accounts; it's supported for Workspace accounts.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `user` | `https://developers.google.com/apps-script/reference/base/user.html` | A representation of the user who should become the new owner. |

#### Return


`https://developers.google.com/apps-script/reference/drive/file#` --- This `https://developers.google.com/apps-script/reference/drive/file#`, for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `setSecurityUpdateEnabled(enabled)`

Sets whether the `https://developers.google.com/apps-script/reference/drive/file#` requires a resource key for access when it's
shared using a link. Eligible files and folders are enabled by default.

Learn more about the [Security update for Google Drive](https://support.google.com/a/answer/10685032).

#### Parameters

| Name | Type | Description |
|---|---|---|
| `enabled` | `Boolean` | Whether to enable the resource key requirement for the `https://developers.google.com/apps-script/reference/drive/file#`. |

#### Return


`https://developers.google.com/apps-script/reference/drive/file#` --- This `https://developers.google.com/apps-script/reference/drive/file#`, for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `setShareableByEditors(shareable)`

Sets whether users with edit permissions to the `https://developers.google.com/apps-script/reference/drive/file#` are allowed to share
with other users or change the permissions. The default for a new `https://developers.google.com/apps-script/reference/drive/file#` is
`true`.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `shareable` | `Boolean` | `true` if users with edit permissions should be allowed to share with other users or change the permissions; `false` if not. |

#### Return


`https://developers.google.com/apps-script/reference/drive/file#` --- This `https://developers.google.com/apps-script/reference/drive/file#`, for chaining.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `setSharing(accessType, permissionType)`

Sets which class of users can access the `https://developers.google.com/apps-script/reference/drive/file#` and what permissions
those users are granted, besides any individual users who have been explicitly given access.

```javascript
// Creates a folder that anyone on the Internet can read from and write to.
// (Domain administrators can prohibit this setting for users of a Google
// Workspace domain.)
const folder = DriveApp.createFolder('Shared Folder');
folder.setSharing(DriveApp.Access.ANYONE, DriveApp.Permission.EDIT);
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `accessType` | `https://developers.google.com/apps-script/reference/drive/access` | which class of users should be able to access the `https://developers.google.com/apps-script/reference/drive/file#` |
| `permissionType` | `https://developers.google.com/apps-script/reference/drive/permission` | the permissions that should be granted to users who can access the `https://developers.google.com/apps-script/reference/drive/file#` |

#### Return


`https://developers.google.com/apps-script/reference/drive/file#` --- this `https://developers.google.com/apps-script/reference/drive/file#`, for chaining

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `setStarred(starred)`

Sets whether the `https://developers.google.com/apps-script/reference/drive/file#` is starred in the user's Drive. The default for
new `https://developers.google.com/apps-script/reference/drive/file#`s is `false`.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `starred` | `Boolean` | `true` if the `https://developers.google.com/apps-script/reference/drive/file#` should be starred in the user's Drive; `false` if not |

#### Return


`https://developers.google.com/apps-script/reference/drive/file#` --- this `https://developers.google.com/apps-script/reference/drive/file#`, for chaining

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive`

*** ** * ** ***

### `setTrashed(trashed)`

Sets whether the `https://developers.google.com/apps-script/reference/drive/file#` is in the trash of the user's Drive. Only the
owner may trash the `https://developers.google.com/apps-script/reference/drive/file#`. The default for new `https://developers.google.com/apps-script/reference/drive/file#`s is `false`.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `trashed` | `Boolean` | `true` if the `https://developers.google.com/apps-script/reference/drive/file#` should be moved to the trash of the user's Drive; `false` if not |

#### Return


`https://developers.google.com/apps-script/reference/drive/file#` --- this `https://developers.google.com/apps-script/reference/drive/file#`, for chaining

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/drive`