I am currently working on a function that will iterate through folders in Google Drive, searching for files (Google Sheets) that match a specific date specified in a table cell. Once a matching file is found, the name of the containing folder is stored in the folderItems[0] and the file's URL is stored in folderItems[1]. The process continues until all matching files within a folder have been identified, after which it moves on to the next folder. These folderItem arrays are then collected in a parent array called "folderItemsContainer," creating a 2-dimensional array that can be easily outputted to a spreadsheet using .setValues().
My main challenge right now is determining the best placement for an increment variable. I need it to only increment when a filename match is found, without causing the loop to stop if no match is detected.
I have experimented with different structures, including switching between for and while loops and adding if statements at strategic points. I've also researched various answers on Stackoverflow, but none seem to directly apply to my situation. As someone who is relatively new to programming, I have tried multiple variations of code, but here is where I stand currently:
// Your function code goes here...
Despite my efforts, the script seems to get stuck in an endless loop and never completes. My goal is to populate the folderItemsContainer array with arrays containing the necessary file information (parent folder name [0] and file URL [1]) for files that match the currentYearPeriod variable. Although I have made progress in refactoring the code, I have yet to find a solution to this issue.