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.
Sync Files Using Google Drive Backup and Sync Simply install Backup and Sync and you can add any folder on your computer to automatically upload all files to Google Drive. You'll also get a new Google Drive folder on your computer.
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 :
var doc = DocumentApp.create('Document Name'),
docFile = DriveApp.getFileById( doc.getId() );
DriveApp.getFolderById('0B3°°°°°°°1lXWkk').addFile( docFile );
DriveApp.getRootFolder().removeFile(docFile);
With document it's a bit different, you first create it then move to the folder:
var doc = DocumentApp.create('Document Name'),
docFile = DriveApp.getFileById( doc.getId() );
DriveApp.getFolderById(foldId).addFile( docFile );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With