Skip to main content
Visitor II
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

    Graduate II
    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.​

    Visitor II
    November 26, 2019

    Thanks for reply

    Visitor II
    November 26, 2019

    which function or stucture i could use for this

    Visitor II
    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)

    Graduate II
    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.​

    Visitor II
    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

    Graduate II
    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.​

    Visitor II
    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.

    Visitor II
    November 30, 2019

    Thanks for support

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

    Visitor II
    January 11, 2023

    Hii Sir,

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