So, this makes absolutely no sense.
- I looked at the code, and there is simply no way for the num_files_ counter to go to 17k without actually counting 17k files. (Which it absolutely did not do according to the serial monitor.)
- The code simply loops through the files, it shouldn’t matter if there are 10, 100 or 100000000. The only difference should be higher numbers and more time. The fact that the number of files matters makes no sense. It would be like a movie changing the second time you watch it. (And I don’t mean any special edition shenanigans.)
So… maybe it’s a compiler bug?
I suggest trying version 3.7.0 of the Arduino-Proffieboard plugin and see if that helps.
Instructions for how to do that can be found in this thread: Gcc 12.3 (new compiler maybe)