There are four ways to create a new file:
The easiest way to create a new file is to use DriveApp
which comes with pure Google Apps Script:
var dir = DriveApp.getFolderById("{dir_id}");
var file = dir.createFile(name, content);
If you do not know exact directory's id you can get the folder by its name:
var dir = DriveApp.getFoldersByName(name).next();
The next()
is there because getFoldersByName()
returns collection of all directories whose names match given value.
Also check DriveApp
docs: https://developers.google.com/apps-script/reference/drive/drive-app