Dump from selected file

My data loggers create new files at midnight, using the date as the file name e.g. 20141213.csv.

I want to be able to download the contents of selected files via serial.

I am using some old zoomkat stuff which uses readString. This enables me to enter six digits - 141213. I can combine this with fixed items to get a String - 20141313.csv.

It looks like what I want, but it appears to need to be a char. How can I sensibly convert it?

// zoomkat 8-6-10 serial I/O string test

#include <SD.h>

const int chipSelect = 4;
String readString;
String stringFive, stringSix, stringSeven;

char dumpName[] = "00000000.CSV";
File dumpFile;

void setup() {
  Serial.begin(9600);
  stringFive = String("20");
  stringSix = String(".csv");   
  pinMode(53, OUTPUT);  //Mega
}

void loop() {
  while (Serial.available()) 
  {
    delay(3);  
    char c = Serial.read();
    readString += c; 
  }// end while

  if (readString.length() >0) {
    Serial.print("readString=    ");
    Serial.println(readString);
    
      stringSeven = stringFive + readString + stringSix;
  
  Serial.print("stringSeven      ");
  Serial.println(stringSeven);
    
   // Do something here!
   getDump();
   // reset string
   readString="";
  } // end if 
}// end loop

void getDump() {
  File dumpFile = SD.open(dumpName);

  
  Serial.print("dumpName =     ");
  Serial.println(dumpName);


  // if the file is available, write to it:
  if (dumpFile) {
    while (dumpFile.available()) {
      Serial.write(dumpFile.read());
    }
    dumpFile.close();
  }  
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening file");
  }
}

How can I sensibly convert it?

Use the toCharArray() method. Or quit relying on Strings at all. The length of the file name is fixed. Store the serial data in a char array.

Thank you.

Here is some working code

// zoomkat 8-6-10 serial I/O string test

#include <SD.h>

const int chipSelect = 4;
String readString;
String stringFive, stringSix, stringSeven;

char dumpName[] = "00000000.CSV";
File dumpFile;

char charBuf [13];

void setup() {
  Serial.begin(9600); // this is not likely to be fast enough
  stringFive = String("20");
  stringSix = String(".csv");   
  pinMode(53, OUTPUT);  //Mega
  
   // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) 
  {
    Serial.println("Card failed");
    // don't do anything more:
    return;
  }
  Serial.println("CARD OK"); 
}

void loop() {
  while (Serial.available()) 
  {
    delay(3);  
    char c = Serial.read();
    readString += c; 
  }// end while

  if (readString.length() >0) {
    
  stringSeven = stringFive + readString + stringSix;
  
 stringSeven.toCharArray(charBuf, 13);
    
   // Do something here!
   getDump();
   // reset string
   readString="";
  } // end if 
}// end loop

void getDump() {
  Serial.print("dumpName =     ");
  Serial.println(dumpName);

  File dumpFile = SD.open(charBuf);
  // if the file is available, write to it:
  if (dumpFile) {
    while (dumpFile.available()) {
      Serial.write(dumpFile.read());
    }
    dumpFile.close();
  }  
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening file");
  }
}
  stringFive = String("20");

This silly mess REALLY needs a comment to not be considered a silly mess. There is NO reason to create an instance of the String class, invoke the copy operator and destroy that instance of the String class just to assign the value "20" to stringFive.

stringFive = "20";
works perfectly well and pisses away far fewer resources.

PaulS:
stringFive = "20";
works perfectly well and pisses away far fewer resources.

Ah, great... I think that's what I needed to see here

http://forum.arduino.cc/index.php?topic=212255.0