(please before dismissing this as already answered, read the full question)
In C++ we can get the file size of a regular file by running std::filesystem::file_size(PATH); But this function does not work on directories, which is my problem.
I am in a situation where I need to know the size of directory "inode", in (most) linux systems the standard size of a directory is 4kB or block size:
$:~/tmp/test$ mkdir ex
$:~/tmp/test$ ls -l
total 4
drwxrwxr-x 2 secret secret 4096 Oct 15 08:43 ex
These 4kB inlcudes space for having a "list" of the file in that directory.
But if the number of files in the directory becomes significantly large, the size of the folder can increase (which is where I am).
I need to be able to track this increase.
So my question is that besides calling ls -l or du from C++ is there a C++-native way of getting the size of the directory?
I am aware that the reason it does not work with std::filesystem::file_size(path) is due file systems different ways of representing directories.