Question: NEEDS DONE IN C, NO OTHER LANGUAGE. ALSO NEEDS TO BE ABLE TO COMPILE IN GCC Extend the readdir program to traverse the file hierarchy

NEEDS DONE IN C, NO OTHER LANGUAGE. ALSO NEEDS TO BE ABLE TO COMPILE IN GCC

Extend the readdir program to traverse the file hierarchy recursively and list all the sub directories and the files in these sub directories. Note that you have to modify the given readdir.c (or readdir_v2.c) program to use a function to perform the file traversal and then invoke it recursively.

---------------------------------------------------------------------------------------------------------------

readdir.c:

#####################

#include #include #include

int main (int argc, char **argv) { struct dirent *dirent; DIR *parentDir;

if (argc < 2) { printf ("Usage: %s ", argv[0]); exit(-1); } parentDir = opendir (argv[1]); if (parentDir == NULL) { printf ("Error opening directory '%s' ", argv[1]); exit (-1); } int count = 1; while((dirent = readdir(parentDir)) != NULL){ printf ("[%d] %s ", count, (*dirent).d_name); count++; } closedir (parentDir); return 0; } ###########################################

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!