To create a new folder in Google Drive using Apps Script, you can use the createFolder()
method of the DriveApp
class. Here’s an example code snippet:
function createNewFolder() { var folderName = 'New Folder'; // Replace with the desired name for the new folder var folder = DriveApp.createFolder(folderName); Logger.log('New folder created with ID: ' + folder.getId()); }
In this code, the createNewFolder
function creates a new folder in Google Drive. The desired name for the new folder is specified by assigning it to the folderName
variable. In this example, it’s set to 'New Folder'
, but you can change it to any desired name.
The createFolder()
method is then called on the DriveApp
object, and the folderName
is passed as an argument. This method creates a new folder in the root directory of Google Drive.
The createFolder()
method returns a Folder
object representing the newly created folder. In this example, it’s assigned to the folder
variable.
To demonstrate the creation of the folder, the getId()
method is called on the folder
object to retrieve the unique ID of the newly created folder. This ID is then logged using Logger.log()
.
You can call the createNewFolder
function from another function or set up a trigger to execute it based on your needs. When executed, it will create a new folder in Google Drive with the specified name and log its ID.
Feel free to modify the code to suit your specific requirements, such as creating the folder in a specific directory or performing additional operations on the folder.