cancel
Showing results for 
Search instead for 
Did you mean: 

How to get size of folder(Directory) in fatfs filesystem

dbgarasiya
Senior II

Hello

I am woking on STM32F779BI controller

I am working with sd card .

I am getting size of text file using f_size(fp) , but how can we get size of folder(Directory)

Best Regards

Dipak Garasiya

10 REPLIES 10

Should be able to infer from structures.

Typically non-root will allocate a cluster at a time, and each entry takes 32 bytes. Problem is LFN will consume multiple and variable number of records. If you want a file count you'll need to enumerate.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
dbgarasiya
Senior II

Thanks for reply

dbgarasiya
Senior II

which function or stucture i could use for this

dbgarasiya
Senior II

i have used structure : FILINFO

but could only be able to give size of file only (text file)

i could not find size of folder(directory)

I think you have to walk the cluster chain to see how many it owns.

What "size" are you trying to determine? Number of files, folders, bytes, or someth​ing else? The FATFS layer doesn't walk the directory automatically as it is time consuming.

Liking your own posts isn't necessary.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
dbgarasiya
Senior II

I am capable to read number of files and folders in sd card using of f_opendir and f_readdir

i could print list of files and folders of sd card on terminal

but want to also print the size of each folder and file also

file size is done by me but not able to find size of folder in (like in bytes)

Thanks for replying

When cataloguing I build tables from the folder content, and then traverse the subfolders.

The allocation unit for a directory is a cluster, you have to chase the chain to determine how many clusters it contains, this isn't tracked/updated in the parent record.​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
dbgarasiya
Senior II

i also want to inform you that

i have find

total size ,available size and free size of sd card use of

f_getfree

function which give number of free clusters.

dbgarasiya
Senior II

Thanks for support

I am capable to find size of directory by followring sbu folder and files included in that