Hi all,
I'm new to C and I have an assignment to write our own linux ls command.
When we type ls -R , it recursively list the target directory. Really have no clue how to do that . Appreciate your help in advance !!

So have you done 'ls' without the -R part already?

Use the stat() function to work out what kind of thing a directory entry is, then call your file listing function recursively.

Here is a c++ example. If all you want to do is display the files then you can easily convert it to C by just removing all the vector stuff and printing the filenames instead of storing them in a list of any kind.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.