You need to open the directory with opendir()
, and loop through the whole directory using readdir()
... and count how many times you do.
Remember that '.' and '..' are special entries and don't count.
If you need to count files only and no directories, you will have to check explicitly in the dir struct (man stat
).
If you need to have the number of files in the folder and its subfolders, then you will have to recurse ("walk") inside the directories - and maybe, depending on the platform, checking for symlinks.