Creates a new file in Drive from a name and content.
class DriveApp method .createFile()
DriveApp is the Apps Script service.
.createFile() is the method name you will see after a dot in your code.
What it does
Why it's used
- Save a CSV or PDF export straight to Drive.
- Generate a text log file after each nightly run.
Common errors
- Forgetting parentheses on createFile. Write DriveApp.createFile(), not DriveApp.createFile or createFile by itself.
- Skipping dots between chained calls. Each step needs a dot, like DriveApp.getFileById(id).createFile().
- Adding spaces where they do not belong. Write DriveApp.createFile(), not DriveApp .createFile(), DriveApp.createFile (), or DriveApp . createFile().
- Wrong capitalization. Use DriveApp and createFile, not driveapp or createfile.
1 Snippets using this method
Explore
Related methods
-
.createFolder()
Creates a new folder in Drive.
-
.makeCopy()
Creates a duplicate of a file in Drive.
-
.addFile()
Moves a file into a folder.
-
.getFileById()
Loads a Drive file by its file ID.
-
.removeFile()
Removes a file from a folder without deleting it.
More Apps Script
1 Better Sheets tutorials
Automatic Screenshots in Apps Script
Related blog posts
Written guides about DriveApp.createFile().