2017-03-30 09:49 AM
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.
Solved! Go to Solution.
2017-04-03 06:25 AM
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 directoryf_opendir (&dir,'mydirectory');
while (1)
{ res_dir = f_readdir(&dir, &fno); if((res_dir==FR_OK)&&(fno.fname[0]!= 0)) { nb_file_dir++; }}
2017-03-30 10:12 AM
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.
2017-03-30 10:21 AM
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
2017-03-31 03:11 AM
Thank you, i'll understand more FATFS functions
2017-03-31 03:13 AM
Thank you Imen, i'm already working with the
FatFs_uSD example, i'll see this manual.
2017-03-31 06:15 PM
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
2017-04-03 06:25 AM
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 directoryf_opendir (&dir,'mydirectory');
while (1)
{ res_dir = f_readdir(&dir, &fno); if((res_dir==FR_OK)&&(fno.fname[0]!= 0)) { nb_file_dir++; }}
2017-04-03 09:31 AM
That will also count sub-directories, you should also check the attributes.
2017-04-11 09:02 AM
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
2024-02-02 11:32 AM
Hi @nechi
I did pretty much the same thing, but I want to create a file with the name of how much files there are in the directory, for that reason I didn't put the code in the while. Here's the code: