Skip to main content
MDevi.1
Associate II
January 13, 2023
Solved

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.

..

This topic has been closed for replies.
ONadr.1
ONadr.1Best answer
Senior III
January 13, 2023

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.

7 replies

ST Employee
January 13, 2023

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
MDevi.1Author
Associate II
January 13, 2023

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
Super User
January 13, 2023

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 on " Best Answer ".
MDevi.1
MDevi.1Author
Associate II
January 13, 2023

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
ONadr.1Best answer
Senior III
January 13, 2023

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
Principal III
January 15, 2023

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
MDevi.1Author
Associate II
January 17, 2023

Thank you for your responses.