7

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.

4

5 Answers 5

17
var parentFolder = DriveApp.getFolderById(parentFolderId);
var newFolder = parentFolder.createFolder("My New Folder Name");
Sign up to request clarification or add additional context in comments.

Comments

4
var parentFolder=DriveApp.getFolderById(DriveApp.getRootFolder().getId());
  var newFolder=parentFolder.createFolder("name folder")

1 Comment

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, 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.
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);

Comments

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.

Comments

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");
 }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.