Skip to content

Trying to increment filename not working #92

@acca84

Description

@acca84

Hello, i'm learning how to use CH376s, i have modified the example "basicUsageSoftSerial" in order to write to a new file named TEST2.TXT if file TEST1.TXT, to TEST3.TXT if TEST2.TXT exists ...

I have made the folllowing modifications:
` case 49: //1

nbfile = 0;    
uint8_t result = 20;
String filename;
while (result == 20) {
  nbfile++;
  //sprintf(filename, "TEST%d.TXT", nbfile);
  filename = "TEST"+ String(nbfile) + ".TXT";
  flashDrive.setFileName(filename.c_str());  //set the file name
  result = flashDrive.openFile();
  Serial.print("resultat ouverture ");
  Serial.println(filename);
 
  flashDrive.closeFile();
}
flashDrive.setFileName(filename.c_str());
flashDrive.openFile();  //open the file

for (int a = 0; a < 20; a++) {               //write text from string(adat) to flash drive 20 times
  flashDrive.writeFile(adat, strlen(adat));  //string, string length
}
flashDrive.closeFile();  //at the end, close the file
printInfo("Done!");
break;`

files are successfully created but are empty (excepted TEST1.TXT)
What did i made wrong please ?
Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions