Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Third International Conference Achids 2011 Daegu Korea April 2011 Proceedings Part 2 Lnai 6592

Authors: Ngoc Thanh Nguyen ,Chong-Gun Kim ,Adam Janiak

2011th Edition

3642200419, 978-3642200410

More Books

Students also viewed these Databases questions

Question

5. Understand how cultural values influence conflict behavior.

Answered: 1 week ago