FFat file system question

Ladies & gentlemen, please forgive my limited understanding of OOP.

Using the Arduino IDE to work on ESP32. Sucssefully using a .txt file to hold some parameters. Now changing stuff around and and got a compiler error that my file name (ctlfile1) was not in scope. Got to looking and realized there are several places where I use:

File myFilename FFat.open("/storageFilename")

This seems to me to be like a multiple definition of "myFilename". I always close the file as soon as I'm finished doing something to it, so I don't think it is actually open multiple places at the same time. It makes me nervous.

What is the actual rule? Does this question make any sense?

Thanks,
Chuck659 in Dallas

Start by doing a little research on the FAT16 file system, then start with a freshly formatted FAT16 SD card. Then try each of your routines one at a time and then put the SD card in your computer and check if it did what it was expected. Do not power down or reset when a file is open, this can cause exactly what you are seeing. This response is to help you get started in solving your problem, not solve it for you.
Good Luck & Have Fun!
Gil

chuck659:
Using the Arduino IDE to work on ESP32. Sucssefully using a .txt file to hold some parameters. Now changing stuff around and and got a compiler error that my file name (ctlfile1) was not in scope. Got to looking and realized there are several places where I use:

File myFilename FFat.open("/storageFilename")

Your error is with ctlfile1; so don't worry about myFilename

chuck659:
This seems to me to be like a multiple definition of "myFilename". I always close the file as soon as I'm finished doing something to it, so I don't think it is actually open multiple places at the same time. It makes me nervous.

Not seeing your code makes it difficult to judge what the effects will be. After opening a file, you should always check if myFilename (in your example) equals NULL (indicating error) or not. And if it's NULL, do not attempt to write to it and do not attempt to close it.

You should write a function that handles the reading from the SD card. That way, you will only have one place where you use File myFilename FFat.open("/storageFilename").