cancel
Showing results for 
Search instead for 
Did you mean: 

Hello Community, I am working on a controller, which has FATFS in it for the SD card management. I am unable find the individual folder size, can anyone tell me, how to get it.

MDevi.1
Associate II
 
1 ACCEPTED SOLUTION

Accepted Solutions
ONadr.1
Senior III

FAT FS has not information about folder data volume. Implicit folder size is number of bytes occupied by folder directory structure (min. one cluster). So, only way is sum all files in foldes and subfolders (as AScha.3 mentioned).

For quick info, you should scan whole file structure when device is connected and create some database in memory or as the file in the medium.

View solution in original post

7 REPLIES 7
Sarra.S
ST Employee

Hello @MDevi.1​ 

you can use the f_stat() function from the ff.h file present in the original source package.

This function will return the size of the folder in bytes. Alternatively, you can also use the f_getfree() function, which will return the number of free clusters on the drive, which can be used to calculate the size of the folder.

Hope that helps!

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

MDevi.1
Associate II

Thank you for your reply, I used these functions, f_stat() is only returning size of file, not the size of folder, and f_getfree() returns overall free space. But my requirement is to find the size of directory/folder and sub-folder. I need to find each sub-folder size individually.

AScha.3
Chief II

so you have to scan the folder you want to know: size of all files added together = your wanted "folder size" ; if subdirect. are there, is up to you , to get size of this folder alone or including subs, then you have to recursively scan subs and subsubs...and sum.

If you feel a post has answered your question, please click "Accept as Solution".
MDevi.1
Associate II

Actually my task is audio recording application, there will be lot files, if i keep on reading them, it consume lot of time. I need to check size of folder before recording, if it crosses the limit, then i have to delete old folders. If i go for keep on reading the all available files and adding their size, checking after that means time taking, so there is a high chance of data loss.

ONadr.1
Senior III

FAT FS has not information about folder data volume. Implicit folder size is number of bytes occupied by folder directory structure (min. one cluster). So, only way is sum all files in foldes and subfolders (as AScha.3 mentioned).

For quick info, you should scan whole file structure when device is connected and create some database in memory or as the file in the medium.

Piranha
Chief II

You keep asking questions about basically the same issue, but you do not provide details, do not participate in discussion and do not listen to what others are saying.

> there will be lot files, if i keep on reading them, it consume lot of time

Then you need to think and come up with a better solution.

MDevi.1
Associate II

Thank you for your responses.