Question: Create an application that takes in a path (relative or absolute) as well as an int and recursively prints out statistics about the files contained
Create an application that takes in a path (relative or absolute) as well as an int and recursively prints out statistics about the files contained in each subdirectory.
Your program should open each subdirectory (opendir).
For each file (readdir), gather the necessary stats (stat).
Each time it encounters a subdirectory, it should recurse.
The integer passed is the max number of files to parse in each directory.
Info to be printed for each file:
User ID of owner.
The % of the total memory in this directory the file takes up.
Number of seconds since last access (time).
void printStats(char* path, int max) {
// DO: Put code here.
}
int main(int argc, char** argv) {
if (argc < 3) {
printf("Wrong number of args, expected 2, given %d", argc - 1);
exit(1);
}
printStats(argv[1], atoi(argv[2]));
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
