Design and implement C/C++ program (taskl2prog.c its executable named task 12prog) in projeet2 to navigate through the directory and all.of its subdirectories (which were created in the previous...

Design and implement C/C++ program (taskl2prog.c its executable named task 12prog) in projeet2 to navigate through the directory and all.of its subdirectories (which were created in the previous task). For each directory entry, provide a type of it (e.g., directory, regular file, symbolic link, etc. with WA or stat call to get the type of each — see APUE ch04 Figure 4.3).For the program output, provide a heading for each step in your program and to the console output so that you can see the execution of your program step by step. Each heading should include a brief message with a time-of-day timestamp.Note. The program does not have any information about the structure ahead of the execution. That is, the program starts from the current work directory, to find aid its subdirectories and files to be listed (output), and then for each subdirectory to be navigated (explored) to find all of its subdirectories and files (recursively).


task11prog.c #include #include #include #include #include #include void list() { struct dirent *de; DIR *dr =opendir("."); if(dr == NULL) { printf("Could not open current directory"); return; } while((de = readdir(dr)) != NULL) { printf("%s\n", de->d_name); } closedir(dr); } void execute(void) { chdir("./project2"); char s[100]; char *args[]={"ls",NULL}; printf("%s\n", getcwd(s,100)); list(); mkdir("dir0",0711); chdir("./dir0"); mkdir("dir1",0711); chdir("./dir1"); FILE *fp = fopen("file1.txt", "w+"); fp = fopen("file2.txt", "w+"); list(); chdir(".."); mkdir("dir2"); chdir("./dir2"); fp = fopen("file3.txt", "w+"); fp = fopen("file4.txt", "w+"); list(); chdir(".."); fp = fopen("link5", "w+"); symlink("./dir2/file4.txt","link5"); fp = fopen("file6.txt", "w+"); list(); } void main(void) { execute(); }
Nov 14, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here