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.
Asked
Active
Viewed 2.9k times
6
-
search this forum as it has been asked answered before – Zig Mandel Jan 14 '17 at 12:34
-
You should google for answers before asking. Here's the duplicate: [GAS-create-folder](http://stackoverflow.com/questions/24225398/create-new-file-in-a-folder-with-apps-script-using-google-advanced-drive-service) – Sujay Phadke Jan 15 '17 at 08:01
-
Possible duplicate of [Create new file in a folder with Apps Script using Google Advanced Drive service](http://stackoverflow.com/questions/24225398/create-new-file-in-a-folder-with-apps-script-using-google-advanced-drive-service) – Sujay Phadke Jan 15 '17 at 08:01
-
look at this one : http://stackoverflow.com/questions/11910734/google-apps-script-how-do-i-create-a-file-in-a-folder/30720190#30720190 – Serge insas Jan 15 '17 at 11:05
5 Answers
16
var parentFolder = DriveApp.getFolderById(parentFolderId);
var newFolder = parentFolder.createFolder("My New Folder Name");

Lee Taylor
- 7,761
- 16
- 33
- 49

Rohan Sharma
- 1,416
- 2
- 14
- 19
4
var parentFolder=DriveApp.getFolderById(DriveApp.getRootFolder().getId());
var newFolder=parentFolder.createFolder("name folder")

double-beep
- 5,031
- 17
- 33
- 41

meed
- 41
- 1
-
Welcome to Stack Overflow! While this code snippet may solve the problem, it doesn't explain why or how it answers the question. Please [include an explanation for your code](//meta.stackexchange.com/q/114762/269535), as that really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – Samuel Philipp Jul 08 '19 at 15:00
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);

DanCue
- 619
- 1
- 8
- 17
0
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.

Serge insas
- 45,904
- 7
- 105
- 131
0
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");
}
}

highpass
- 163
- 1
- 7