Pages: [1]   Go Down
Author Topic: SD Filenames  (Read 508 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 41
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I keep getting errors when I use SD.mkdir. This is my code:
Code:
if(char(serialReceived) == '\n') {
        Serial.print("MKDIR: ");
        Serial.println(serialCommand);
        Serial.println(serialCommand.length());
        char sen[serialCommand.length()+1];
        for(int i = 0; i < serialCommand.length(); i++) {
          sen[i] = serialCommand.charAt(i);
        }
        if(SD.mkdir(sen)) {
          Serial.write(6);
        } else {
          Serial.write(21);
        }
        serialState = 0;
        serialCommand = "";
      } else {
        serialCommand += char(serialReceived);
      }

When I run this code, I get that SD.mkdir(sen) returns false.
Logged

Offline Offline
Edison Member
*
Karma: 48
Posts: 1617
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You need to store a null at the end of the string. Try this:
Code:
        int i;
        for(i = 0; i < serialCommand.length(); i++) {
          sen[i] = serialCommand.charAt(i);
        }
        sen[i] = 0;

You should also make sure that the names you use are valid.
Pete
Logged

Where are the Nick Gammons of yesteryear?

Pages: [1]   Go Up
Jump to: