I wrote the code below to create the folder "Second Bottom 1" and "Second Bottom 2" under the folder "Second", but it is created in the same hierarchy as "Second" as shown in the attached image. Why?
var folder=DriveApp.createFolder("first");
var folder1 = folder.addFolder(folder.createFolder("second"));
var folder2 = folder1.addFolder(folder.createFolder("second bottom 1"));
var folder2 = folder1.addFolder(folder.createFolder("second bottom 2"));
If you take out the part where you are creating the folder itself...
var folder=DriveApp.createFolder("first");
folder.createFolder("Second")
folder.createFolder("2nd bottom 1")
folder.createFolder("2nd bottom")
All folders are created under folder
(first).This is why they are created in the same hierarchy.
Also, addFolder()
is used to make the folder of arguments belong to more than one folder, so it should not be necessary in this case.
I think the following code will be the desired behavior.
var folder1 = DriveApp.createFolder("first");
var folder2 = folder1.createFolder("second");
folder2.createFolder("2nd bottom 1";
folder2.createFolder("2nd bottom");
© 2024 OneMinuteCode. All rights reserved.