List Directory


The following program is a simple version of the ls command that lists the files in a directory. It takes no options. If a path argument is given, it lists the contents of that directory; otherwise, it lists the contents of the current directory.

The program demonstrates the following library calls:

opendir
Open a directory
readdir
Read the next entry in a directory
closedir
Close a directory stream

The complete source code and Makefile for these programs is available as a zip file.

list_dir.c