Skip to main content
Visitor II
March 30, 2017
Solved

SD Card

  • March 30, 2017
  • 5 replies
  • 2888 views
Posted on March 30, 2017 at 18:49

Hi, 

I'm using the cubeF4 to work on FATFS application and i'm searching for a function in FATFS library that can return the content of the SD Card: number of files and their names.  

Thank you.

    This topic has been closed for replies.
    Best answer by nechi
    Posted on April 03, 2017 at 15:25

    Thank you all, all your suggestions were helpful 

    I saved files in a directory created in the SD Card and i just used the function '

    f_readdir' 

    into a loop to count files in my directory

    f_opendir (&dir,'mydirectory');

    while (1)

    {

       res_dir = f_readdir(&dir, &fno);

       if((res_dir==FR_OK)&&(fno.fname[0]!= 0))

       {

          nb_file_dir++;

       }

    }

    5 replies

    Graduate II
    March 30, 2017
    Posted on March 30, 2017 at 19:12

    You'll have to write such code, the FATFS library provides functions like f_opendir, f_readdir, you'd use these to process and count files in the current directory, and you'd need recurse and descend into the directories you encounter at each level.

    nechiAuthor
    Visitor II
    March 31, 2017
    Posted on March 31, 2017 at 10:11

    Thank you, i'll understand more FATFS functions 

    Technical Moderator
    March 30, 2017
    Posted on March 30, 2017 at 19:21

    Hi,

    There is FatFs_uSD example on STM32CubeF4 firmware package that can help you to use most of the features offered by FatFs and to configure a microSD drive.

    You can get help from the User manual UM1721'Developing Applications on STM32Cube with FatFs'

    Imen

    nechiAuthor
    Visitor II
    March 31, 2017
    Posted on March 31, 2017 at 10:13

    Thank you Imen, i'm already working with the 

    FatFs_uSD example, i'll see this manual.

    Visitor II
    April 1, 2017
    Posted on April 01, 2017 at 03:15

    http://elm-chan.org/fsw/ff/en/readdir.html

    the code example doesn't print the count, but it does walk the directory tree and print the contents

    nechiAuthorAnswer
    Visitor II
    April 3, 2017
    Posted on April 03, 2017 at 15:25

    Thank you all, all your suggestions were helpful 

    I saved files in a directory created in the SD Card and i just used the function '

    f_readdir' 

    into a loop to count files in my directory

    f_opendir (&dir,'mydirectory');

    while (1)

    {

       res_dir = f_readdir(&dir, &fno);

       if((res_dir==FR_OK)&&(fno.fname[0]!= 0))

       {

          nb_file_dir++;

       }

    }

    Graduate II
    April 3, 2017
    Posted on April 03, 2017 at 16:31

    That will also count sub-directories, you should also check the attributes.

    nechiAuthor
    Visitor II
    April 11, 2017
    Posted on April 11, 2017 at 18:02

    My SDcard is 8GB with one directory where i save files from the F4 discovery and it works well. Now i faced some problems, i added an other directory (2.6Gbyte) in the sd card and it's not related to the first one. when i save new files in the first directory i notice that the old ones are overwritten with 'UUUUUU...'. Did you know this issue please? I can't understand why they are modified even though i didn't opened any of them with the stm32 i just count the number of the existing files in the directory and then i create new ones