As you perhaps already know, in Linux : "everything is a file". Indeed, even folders are actually files! The two most important type of files are regular files and folders.
Moreover, the structures of files in Linux can be represented as a tree, with "/" the root of all files.
You must implement a function called get_number_of_files
which will take a path in argument,
and return the number of regular files contained in this path (or in sub-folder).
If the path doesn't exist, your function should return -1;
Hint : Implementing a recursive functions is easier and efficient !
For example:
- For the folder Documents, which contains : a, b et c (3 regular files) :
get_number_of_files("./Documents")
returns3
- For the folder Home, which contains the folder Documents (see above), and the folder Downloads which itself contains : d (regular file) et y (folder). y contains only e (regular file).
get_number_of_files("./Home")
returns5
N.B.: We recommend you to use these functions of the standard library : stat, S_ISREG, opendir, readdir.
Be careful that readdir return also the path to "."
et ".."
in a folder. You should ignore these path, otherwise, it will create infinite loops.