Finds files in Drive that match a given name.
class DriveApp method .getFilesByName()
DriveApp is the Apps Script service.
.getFilesByName() is the method name you will see after a dot in your code.
What it does
Why it's used
- Find Invoice Template.pdf without asking the user to browse.
- Grab the latest file when everyone uses the same name.
Common errors
- Forgetting parentheses on getFilesByName. Write DriveApp.getFilesByName(), not DriveApp.getFilesByName or getFilesByName by itself.
- Skipping dots between chained calls. Each step needs a dot, like DriveApp.getFileById(id).getFilesByName().
- Adding spaces where they do not belong. Write DriveApp.getFilesByName(), not DriveApp .getFilesByName(), DriveApp.getFilesByName (), or DriveApp . getFilesByName().
- Wrong capitalization. Use DriveApp and getFilesByName, not driveapp or getfilesbyname.
Explore
Related methods
-
.getFoldersByName()
Finds folders in Drive that match a given name.
-
.searchFiles()
Searches Drive files using a query string.
-
.getFileById()
Loads a Drive file by its file ID.
-
.getFolderById()
Loads a Drive folder by its folder ID.
-
.addFile()
Moves a file into a folder.
More Apps Script
Better Sheets tutorials
No tagged tutorials yet. Fetch Apps Script from the harvest table and this page fills automatically.
Related blog posts
Written guides about DriveApp.getFilesByName().