SdFat variables + constants in path names

I'm a novice Arduino coder. Can someone please explain if it's possible to include variables in a path name when opening files using the SdFat library? For example, I want to open "mario/config.txt" kind of like this:

char folder[] = "mario"; + "/config.txt", O_READ))

But of course that doesn't concatenate properly. I discovered I can concatenate the two strings using strcat and pass that to, but that eats up 11 bytes of SRAM (/config.txt) with static text. I'm very low on SRAM so every byte counts. Any suggestions?

But of course that doesn't concatenate properly.

Of course.

  • is not a concatenation operator unless a class provides it. There are no class instances involved in your code, so no class that might provide a concatenation operator.

sprintf() bears investigation.

Thanks for the pointer, PaulS.

In case any other noobs ever need a solution to this, it turns out that paths are relative to the current working directory. All I needed to do was store the folder name as a var, change my working directory to that, and then load my config.txt file.

char folder[] = "mario";
sd.chdir(folder);"config.txt", O_READ);