I need the file "test01.bmp" to be read just once at the beginning of the program, and the other 4 files are read in a loop afterwards.
My problem appears when I start using directories. I created in the sd card the directory "RAI", and put the files inside of this directory. Also changed the sketch to:
Probably there's an error in the code, most probably in that part that you're hiding from us.
Always post complete code! If your sketch is complex, try to reduce it to shorter sketch, that still shows the same symptoms but don't leave away parts needed for us to compile the same code.
not trying to hide anything. I simply posted what I though it would be neccesary in order to correct the mistake, but you are probably right; the mistake must be somewhere else...
And how long is your new filename with a directory, including the trailing nul?
You might be surprised what you get if you Serial.print(temp)
It may be better to use Filename.c_str() which returns a pointer. I don't think the SD.open() function modifies the string. Ideally, get rid of the String class in your code. It causes memory fragmentation.