How do I create a Google document in a Google Drive folder?
I know that I can create a file in a folder like this.
var folder = DriveApp.createFolder("A Folder")
folder.createFile("filename.file", "Some text")
But how I can create a document in a folder using Google Apps Script.
With document it's a bit different, you first create it then move to the folder:
To add to @Kriggs answer.
To remove from the root folder:
DriveApp.getRootFolder().removeFile(file)
Otherwise, it will be in the root level and the new location.
The other answer is correct but the file will exist in your folder AND in your "drive" folder (the root folder).
To avoid that, simply remove it from there !
code :
This is how to create a new Google Doc in a specific folder. When the Doc is created, the mime type must be set.
Note that this code does NOT first create a Doc file, move it, and then delete the file in the Root Drive. This code creates a new Google Doc type file directly in a folder.
You will need to use the Advanced Drive API. It must be enabled in two places.
Code: