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.FileStart 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.
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.FileShow example code
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.FileShow example code
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.FileShow example code
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
- addCommenter(emailAddress: string): DriveApp.File
- addCommenter(user: User): DriveApp.File
addCommenters
- addCommenters(emailAddresses: string[]): DriveApp.File
addEditor
- addEditor(emailAddress: string): DriveApp.File
- addEditor(user: User): DriveApp.File
addEditors
- addEditors(emailAddresses: string[]): DriveApp.File
addViewer
- addViewer(emailAddress: string): DriveApp.File
- addViewer(user: User): DriveApp.File
addViewers
- addViewers(emailAddresses: string[]): DriveApp.File
getAccess
- getAccess(email: string): DriveApp.Permission
- getAccess(user: User): DriveApp.Permission
getAs
- getAs(contentType: string): Blob
getBlob
- getBlob(): Blob
getDateCreated
- getDateCreated(): Date
getDescription
- getDescription(): string | null
getDownloadUrl
- getDownloadUrl(): string
getEditors
- getEditors(): User[]
getId
- getId(): string
getLastUpdated
- getLastUpdated(): Date
getMimeType
- getMimeType(): string
getName
- getName(): string
getOwner
- getOwner(): User
getParents
- getParents(): DriveApp.FolderIterator
getResourceKey
- getResourceKey(): string
getSecurityUpdateEligible
- getSecurityUpdateEligible(): boolean
getSecurityUpdateEnabled
- getSecurityUpdateEnabled(): boolean
getSharingAccess
- getSharingAccess(): DriveApp.Access
getSharingPermission
- getSharingPermission(): DriveApp.Permission
getSize
- getSize(): number
getTargetId
- getTargetId(): string | null
getTargetMimeType
- getTargetMimeType(): string | null
getTargetResourceKey
- getTargetResourceKey(): string | null
getThumbnail
- getThumbnail(): Blob | null
getUrl
- getUrl(): string
getViewers
- getViewers(): User[]
isShareableByEditors
- isShareableByEditors(): boolean
isStarred
- isStarred(): boolean
isTrashed
- isTrashed(): boolean
makeCopy
- makeCopy(): DriveApp.File
- makeCopy(name: string): DriveApp.File
- makeCopy(destination: DriveApp.Folder): DriveApp.File
- makeCopy(name: string, destination: DriveApp.Folder): DriveApp.File
moveTo
- moveTo(destination: DriveApp.Folder): DriveApp.File
removeCommenter
- removeCommenter(emailAddress: string): DriveApp.File
- removeCommenter(user: User): DriveApp.File
removeEditor
- removeEditor(emailAddress: string): DriveApp.File
- removeEditor(user: User): DriveApp.File
removeViewer
- removeViewer(emailAddress: string): DriveApp.File
- removeViewer(user: User): DriveApp.File
revokePermissions
- revokePermissions(emailAddress: string): DriveApp.File
- revokePermissions(user: User): DriveApp.File
setContent
- setContent(content: string): DriveApp.File
setDescription
- setDescription(description: string): DriveApp.File
setName
- setName(name: string): DriveApp.File
setOwner
- setOwner(emailAddress: string): DriveApp.File
- setOwner(user: User): DriveApp.File
setSecurityUpdateEnabled
- setSecurityUpdateEnabled(enabled: boolean): DriveApp.File
setShareableByEditors
- setShareableByEditors(shareable: boolean): DriveApp.File
setSharing
- setSharing(accessType: DriveApp.Access, permissionType: DriveApp.Permission): DriveApp.File
setStarred
- setStarred(starred: boolean): DriveApp.File
setTrashed
- 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