'Create a new folder in Drive using Google App Script
Is there a way to create a google app script to create a new folder in Google Drive that is NOT IN THE ROOT FOLDER? A script to move a folder in the root to a particular folder will also do.
Solution 1:[1]
var parentFolder=DriveApp.getFolderById(DriveApp.getRootFolder().getId());
var newFolder=parentFolder.createFolder("name folder")
Solution 2:[2]
If you are going to need the folder ID to let's say move or create a file there you can do the following.
var parentFolder = DriveApp.getFolderById(parentFolderId);
var newFolderID = parentFolder.createFolder("New Folder Name").getId();
Then you can do this
DriveApp.getFolderById(newFolderID);
Solution 3:[3]
The folder object has a createFolder method, see doc here.
so you should simply get the folder you want and create the new one from there.
Solution 4:[4]
getFolderById seems to be removed.
Try this:
function createFolder(parentFolderName)
{
var folders = DriveApp.getFolders();
while (folders.hasNext()) {
var folder = folders.next();
if(parentFolderName == folder.getName())
folder.createFolder("Folder Name");
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | double-beep |
| Solution 2 | DanCue |
| Solution 3 | Serge insas |
| Solution 4 | highpass |
