Looking for google-apps-script Answers? Try Ask4KnowledgeBase
Looking for google-apps-script Keywords? Try Ask4Keywords

google-apps-script Add a folder to the root drive


Example

function DriveAppAddFolder(child) {//Adds file to the root drive in Google Drive
  var body,returnedFolder;//Declare variable names

  if (!child) {
    body = "There is no folder";
    MailApp.sendEmail(Session.getEffectiveUser().getEmail(), "", "Error Adding Folder!", body)
    return;
  };
    
  returnedFolder = DriveApp.addFolder(child);//Add a folder to the root drive
  
  Logger.log('returnedFolder: ' + returnedFolder);//Print the folder results to the Logs
};


function createNewFolderInGoogleDrive() {
  var folder,newFolderName,timeStamp,dateTimeAsString;
  
  timeStamp = new Date();//Create a new date
  dateTimeAsString = timeStamp.toString().slice(0,15);
  
  newFolderName = 'Test Folder Name ' + dateTimeAsString;//Create new folder name with date/time appended to name
  
  folder = DriveApp.createFolder(newFolderName);//Create a new folder
  DriveAppAddFolder(folder);//Call a function and pass a folder to the function
};