Skip to content

Object reference

Drive file

A DriveApp.File is one item in Google Drive, such as a Doc, Sheet, or PDF. Open it with DriveApp.getFileById(id) to read its metadata, copy it, or export a PDF.

DriveApp.File

Start here

Get this object first

Get a file by its ID when you already know which file the script should work with. You can copy the ID from the file URL in Drive.

Code.gs
function showFileById() {
  const file = DriveApp.getFileById('REPLACE_WITH_FILE_ID');
  Logger.log(file.getName());
}

Then use it

Common actions

Choose an action, then open its example only when you need the code.

Log the name, URL, size, and type

This reads four details about the file and does not change it.

DriveApp.File
Show example code
Code.gs
function logFileDetails() {
  const file = DriveApp.getFileById('REPLACE_WITH_FILE_ID');
  Logger.log('Name: ' + file.getName());
  Logger.log('URL: ' + file.getUrl());
  Logger.log('Size in bytes: ' + file.getSize());
  Logger.log('MIME type: ' + file.getMimeType());
}

Make a copy of the file (this creates a new file)

This creates a new copy of the file in Drive with "Copy of" added to its name. The original file is not changed.

DriveApp.File
Show example code
Code.gs
function copyFile() {
  const file = DriveApp.getFileById('REPLACE_WITH_FILE_ID');
  const copy = file.makeCopy('Copy of ' + file.getName());
  Logger.log('Created: ' + copy.getUrl());
}

Get a Doc as a PDF blob

This converts a Google Doc file to PDF data in memory and logs its size. It does not save a new file to Drive.

DriveApp.File
Show example code
Code.gs
function logDocAsPdfSize() {
  const file = DriveApp.getFileById('REPLACE_WITH_FILE_ID');
  const pdfBlob = file.getAs('application/pdf');
  Logger.log('PDF size in bytes: ' + pdfBlob.getBytes().length);
}

Technical reference

Exact names and signatures

Generated runtime and signature facts stay separate from the beginner actions above. Open method details only when you need them.

At a glance

Service
DriveApp
Reference symbol
DriveApp.File
Object
File
Runtime
From signature data

Methods and signatures

Browse 49 methods

addCommenter

From signature data Google source
  • addCommenter(emailAddress: string): DriveApp.File
  • addCommenter(user: User): DriveApp.File

addCommenters

From signature data Google source
  • addCommenters(emailAddresses: string[]): DriveApp.File

addEditor

From signature data Google source
  • addEditor(emailAddress: string): DriveApp.File
  • addEditor(user: User): DriveApp.File

addEditors

From signature data Google source
  • addEditors(emailAddresses: string[]): DriveApp.File

addViewer

From signature data Google source
  • addViewer(emailAddress: string): DriveApp.File
  • addViewer(user: User): DriveApp.File

addViewers

From signature data Google source
  • addViewers(emailAddresses: string[]): DriveApp.File

getAccess

From signature data Google source
  • getAccess(email: string): DriveApp.Permission
  • getAccess(user: User): DriveApp.Permission

getAs

From signature data Google source
  • getAs(contentType: string): Blob

getBlob

From signature data Google source
  • getBlob(): Blob

getDateCreated

From signature data Google source
  • getDateCreated(): Date

getDescription

From signature data Google source
  • getDescription(): string | null

getDownloadUrl

From signature data Google source
  • getDownloadUrl(): string

getEditors

From signature data Google source
  • getEditors(): User[]

getId

From signature data Google source
  • getId(): string

getLastUpdated

From signature data Google source
  • getLastUpdated(): Date

getMimeType

From signature data Google source
  • getMimeType(): string

getName

From signature data Google source
  • getName(): string

getOwner

From signature data Google source
  • getOwner(): User

getParents

From signature data Google source
  • getParents(): DriveApp.FolderIterator

getResourceKey

From signature data Google source
  • getResourceKey(): string

getSecurityUpdateEligible

From signature data Google source
  • getSecurityUpdateEligible(): boolean

getSecurityUpdateEnabled

From signature data Google source
  • getSecurityUpdateEnabled(): boolean

getSharingAccess

From signature data Google source
  • getSharingAccess(): DriveApp.Access

getSharingPermission

From signature data Google source
  • getSharingPermission(): DriveApp.Permission

getSize

From signature data Google source
  • getSize(): number

getTargetId

From signature data Google source
  • getTargetId(): string | null

getTargetMimeType

From signature data Google source
  • getTargetMimeType(): string | null

getTargetResourceKey

From signature data Google source
  • getTargetResourceKey(): string | null

getThumbnail

From signature data Google source
  • getThumbnail(): Blob | null

getUrl

From signature data Google source
  • getUrl(): string

getViewers

From signature data Google source
  • getViewers(): User[]

isShareableByEditors

From signature data Google source
  • isShareableByEditors(): boolean

isStarred

From signature data Google source
  • isStarred(): boolean

isTrashed

From signature data Google source
  • isTrashed(): boolean

makeCopy

From signature data Google source
  • makeCopy(): DriveApp.File
  • makeCopy(name: string): DriveApp.File
  • makeCopy(destination: DriveApp.Folder): DriveApp.File
  • makeCopy(name: string, destination: DriveApp.Folder): DriveApp.File

moveTo

From signature data Google source
  • moveTo(destination: DriveApp.Folder): DriveApp.File

removeCommenter

From signature data Google source
  • removeCommenter(emailAddress: string): DriveApp.File
  • removeCommenter(user: User): DriveApp.File

removeEditor

From signature data Google source
  • removeEditor(emailAddress: string): DriveApp.File
  • removeEditor(user: User): DriveApp.File

removeViewer

From signature data Google source
  • removeViewer(emailAddress: string): DriveApp.File
  • removeViewer(user: User): DriveApp.File

revokePermissions

From signature data Google source
  • revokePermissions(emailAddress: string): DriveApp.File
  • revokePermissions(user: User): DriveApp.File

setContent

From signature data Google source
  • setContent(content: string): DriveApp.File

setDescription

From signature data Google source
  • setDescription(description: string): DriveApp.File

setName

From signature data Google source
  • setName(name: string): DriveApp.File

setOwner

From signature data Google source
  • setOwner(emailAddress: string): DriveApp.File
  • setOwner(user: User): DriveApp.File

setSecurityUpdateEnabled

From signature data Google source
  • setSecurityUpdateEnabled(enabled: boolean): DriveApp.File

setShareableByEditors

From signature data Google source
  • setShareableByEditors(shareable: boolean): DriveApp.File

setSharing

From signature data Google source
  • setSharing(accessType: DriveApp.Access, permissionType: DriveApp.Permission): DriveApp.File

setStarred

From signature data Google source
  • setStarred(starred: boolean): DriveApp.File

setTrashed

From signature data Google source
  • setTrashed(trashed: boolean): DriveApp.File

Need the whole workflow?

Return to a task guide

Task guides cover setup, permissions, expected results, and troubleshooting as well as object methods.

Browse Google Drive tasks