I am trying to create a google doc in a specific folder held in the variable chapterOne.
I've googled and googled and the closest I've found to an answer is this code here:
function Test() {
DocsList.createFolder('Folder1').createFolder('Subfolder1').createFile('File1', 'Empty');
}
But the problem is that it creates a file, not a google doc. What I'm looking for would call DocumentApp somehow...
DocsList is depreciated now, so for anyone who may come across this thread, here is an updated answer:
function createDoc() {
// Creates doc in root directory
var doc = DocumentApp.create('MyDocument');
var docFile = DriveApp.getFileById(doc.getId());
// Copy doc to the directory we want it to be in. Delete it from root.
DriveApp.getFoldersByName('Subfolder1').next().addFile(docFile);
DriveApp.getRootFolder().removeFile(docFile);
// Returns the ID of the newly created Doc
return DriveApp.getFilesByName('MyDocument').next().getId();
}
Here is a link to the post where I found this answer: Create a Google Doc file directly in a Google Drive folder
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