Question: Traverse the directory structure from current directory (recursively, that is, to traverse left-to-right depth-first manner) and (1) to print the current path (with pwd command

Traverse the directory structure from current directory (recursively, that is, to traverse left-to-right depth-first manner) and (1) to print the current path (with pwd command using system("pwd") call) and (2) to print any file/directory entries (with ls command, using system("ls") call). Your program should print the result of each pwd from current-directory path name, then to the path name of dir1, and then dir4 and so on.

Reference: https://www.gnu.org/software/libc/manual/html_node/Running-a-Command.html

http://man7.org/linux/man-pages/man3/system.3.html

/* for example, in your program, to run time command */

#include

int main(void)

{

int rc;

rc = system("pwd");

exit(0);

}

/* Example2. to create a file using touch command */

#include

int main(void)

{

int result;

result = system("touch newfile");

}

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!

Q:

2x