Answered step by step
Verified Expert Solution
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 listFilesconst char dirPath;
int mainint argc, char const argv
if argc
No argument, print the current working directory WITHOUT recursion
char cwd;
if getcwdcwd sizeofcwd NULL
listFilescwd;
else
perrorgetcwd this is error";
exitEXITFAILURE;
else if argc
Argument provided, print that directory RECURSIVELY
listFilesargv;
else
Too many arguments, display an error message
fprintfstderr "Usage: s directory
argv;
exitEXITFAILURE;
return EXITSUCCESS;
void listFilesconst char dirPath
DIR dir;
struct dirent entry;
if dir opendirdirPath NULL
while entry readdirdir NULL
if entrydname
Ignore hidden files and directories
printfs
entrydname;
closedirdir;
else
perrorthere is no subdir it's an error";
exitEXITFAILURE;
re witre my code with diffrent stuatuer. code in c
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started