Skip to main content
dbgarasiya
Senior
November 26, 2019
Question

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

  • November 26, 2019
  • 7 replies
  • 3265 views

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.

7 replies

Tesla DeLorean
Guru
November 26, 2019

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 VenmoUp vote any posts that you find helpful, it shows what's working..
dbgarasiya
Senior
November 26, 2019

Thanks for reply

dbgarasiya
Senior
November 26, 2019

which function or stucture i could use for this

dbgarasiya
Senior
November 26, 2019

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
November 26, 2019

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 VenmoUp vote any posts that you find helpful, it shows what's working..
dbgarasiya
Senior
November 26, 2019

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
November 26, 2019

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 VenmoUp vote any posts that you find helpful, it shows what's working..
dbgarasiya
Senior
November 26, 2019

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
November 30, 2019

Thanks for support

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

MDevi.1
Associate II
January 11, 2023

Hii Sir,

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