I am doing a apps script app that will store some data inside folders that I pretend to create depending on current date, i.e, the script will look if inside a parent folder with known id is a folder named with current year, if there is not then will create the folder, then will check which month is it and create month folder inside the year folder, last it will create a custom folder with custom data inside month folder. The problem is that I just could create the year folder with the following code:
function createFolder(date){
var year = date.substring(6,10);
var month = meses[date.substring(3,5)];
var yearFolder
var parentFolder = DriveApp.getFolderById(parentFolderId);
// Gets FolderIterator for yearFolder
yearFolders = parentFolder.getFoldersByName(year);
/* Checks if FolderIterator has Folders with given name
Assuming there's only a yearFolder with given name... */
while (yearFolders.hasNext()) {
yearFolder = yearFolders.next();
}
if (!yearFolder) {parentFolder.createFolder(year);
}
}
i want to use the same code to create the month and custom folders but the problem is that i cant retrieve the id of the created year folder and then the month one. How can i do it?