1

I want to store some data to sd card using FATFS (STM32 micro-controller), but i have a problem i want to create a new file every time if there is already a file (from older experiments). So can someone give an example how to do that? For example if there is already an existing file called TEST1.TXT on the sd card, the program should create TEST2.TXT, if TEST2.TXT exist then TEST3.TXT and so on...

    FATFS myFATAFS;
FIL myFILE;

unsigned int testByte;

    if(f_mount(&myFATAFS,SD_Path, 1)== FR_OK){


    char myPath[] = "TEST1.TXT\n";
    f_open(&myFILE, myPath, FA_WRITE | FA_CREATE_NEW);

        //do something  

    f_close(&myFILE);
     HAL_GPIO_TogglePin(LED2_GPIO_type, LED2_GPIO_pin);
}
  • read the directory, then find the last file number, create a new one with the new number. BTW show us your effort. FATFS documentation shows how to read the directory. – 0___________ Mar 04 '20 at 17:26
  • especially `Directory Access f_opendir - Open a directory f_closedir - Close an open directory f_readdir - Read a directory item f_findfirst - Open a directory and read the first item matched f_findnext - Read a next item matched` – 0___________ Mar 04 '20 at 17:35

0 Answers0