Go Down

Topic: How to open correct file in a list of files using "name + number" in filename (Read 533 times) previous topic - next topic

JO3RI

Having multiple files on an SD card, I can't seem to figure out how to open the correct file. Let's say I have 256 files like this:

Code: [Select]
ajob1.txt
ajob2.txt
ajob3.txt
...
ajob256.txt


Now the number is the ID I get from somewhere else:

byte ID = x
for (int x = 1; x < 257; x++)
  {
  }
then my filename is something like ajob ID .txt

but how do I get to replace the ID by the number so I can use this

Code: [Select]
myFile = SD.open("ajob ID .txt");
  if (myFile) {
    Serial.println("ajob ID .txt:");
   
    // read from the file until there's nothing else in it:
    while (myFile.available()) {
    Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();


http://www.JO3RI.be

Nederlandstalige sectie - http://arduino.cc/forum/index.php/board,77.0.html -

PaulS

Code: [Select]
int jobNumber =14;
char fileName[12];
sprintf(fileName, "ajob%d.txt", jobNumber);


will result in fileName containing "ajob14.txt", which can be used as an argument to SD.open().

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy