Error opening log.csv - linked to array of files?

Hi all,

I'm having issues with datalogging. I'm building on this older thread. I created an array of files and I want to open it these files to write on them. However, I get an error to opening the file. I don't know if this is because I am supposed to use an array of pointers to files instead of an array of files, or if it is due to the name of the file, or due to any other issue. I made sure that the filenames were short (less than 8 characters) and contained only letters and numbers. Here is the code snippet (within the loop() function and within a state):

File filePointers[CellN]; //Array of 4 files, one for each cell
char filename_cell[32];
char completefilename_cell[40];
sprintf (filename_cell, "S%02iC%02i.CSV", NN, thisCell + 1); //create filename
sprintf (completefilename_cell, "%s/%s/%s", foldername, datafoldername, filename_cell); //this uses previously made foldernames and gives: /201216/Data/S01C01.CSV
filePointers[thisCell] = SD.open(completefilename_cell, "r"); 

if (filePointers[thisCell]) {
//write stuff
}
else {
    Serial.println("error opening log.csv"); // this is the error that pops up!
}

Any clue where I should look for to solve this?

Yes.
add a line:

    Serial.println(completefilename_cell);

Prove to us that your sprint() is doing what you think it's doing when building completefilename_cell.

The error message would be a lot more useful if it printed the name of the file being opened instead of "log.csv"

Pete

Hi, thanks a lot. I did this - the filename in my comment line //this uses previously made foldernames and gives: /201216/Data/S01C01.CSV is actually a copy-paste of the serial monitor - so the completefilename_cell is built how I expected it

Not sure you can use "r" for the mode parameter in SD.Open()

Examples show :

SD.open(filename, FILE_WRITE);

@Pete: Thanks, I edited the code.
@Dan95: You're right, I edited the code. However this didn't solve the issue

I don't know what happens if the folder doesn't exist.
You could try eliminating the folder file path and just try opening the file at the root level to see if it works.
you could also test for folder existence with

if SD.exists(foldername)
{
SD.open(file);
}

Here is the code snippet

Are you looking for an answer snippet? I didn't think so.