Question: #include #include #include #include #include void listFiles ( const char * dirPath ) ; int main ( int argc, char const * argv [ ]

#include
#include
#include
#include
#include
void listFiles(const char *dirPath);
int main(int argc, char const *argv[]){
if (argc ==1){
// No argument, print the current working directory WITHOUT recursion
char cwd[1024];
if (getcwd(cwd, sizeof(cwd))!= NULL){
listFiles(cwd);
} else {
perror("getcwd() this is error");
exit(EXIT_FAILURE);
}
} else if (argc ==2){
// Argument provided, print that directory RECURSIVELY
listFiles(argv[1]);
} else {
// Too many arguments, display an error message
fprintf(stderr, "Usage: %s [directory]
", argv[0]);
exit(EXIT_FAILURE);
}
return EXIT_SUCCESS;
}
void listFiles(const char *dirPath){
DIR *dir;
struct dirent *entry;
if ((dir = opendir(dirPath))!= NULL){
while ((entry = readdir(dir))!= NULL){
if (entry->d_name[0]!='.'){
// Ignore hidden files and directories
printf("%s
", entry->d_name);
}
}
closedir(dir);
} else {
perror("there is no subdir it's an error");
exit(EXIT_FAILURE);
}
}
re witre my code with diffrent stuatuer. code in c

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!