Skip to main content
dbgarasiya
Senior
Nov 26, 2019 8:36 AM UTC
Question

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

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

This topic has been closed for replies.

10 replies

Tesla DeLorean
Guru
Nov 26, 2019 9:33 AM UTC

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
dbgarasiya
Senior
Nov 26, 2019 9:37 AM UTC

Thanks for reply

dbgarasiya
Senior
Nov 26, 2019 9:41 AM UTC

which function or stucture i could use for this

dbgarasiya
Senior
Nov 26, 2019 9:42 AM UTC

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)

Tesla DeLorean
Guru
Nov 26, 2019 10:18 AM UTC

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
dbgarasiya
Senior
Nov 26, 2019 10:24 AM UTC

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

Tesla DeLorean
Guru
Nov 26, 2019 10:33 AM UTC

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
dbgarasiya
Senior
Nov 26, 2019 10:34 AM UTC

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
Nov 30, 2019 4:50 AM UTC

Thanks for support

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

MDevi.1
Associate II
Jan 11, 2023 5:08 AM UTC

Hii Sir,

Can you tell clearly, which commands you have used to read the directory size.