Reading and Deleting Directories
Explore how to read directory entries in UNIX by using opendir, readdir, and closedir system calls. Understand the structure of directory entries and how to retrieve detailed file information with stat. Learn the rules for safely deleting directories using rmdir, including why directories must be empty before removal.
We'll cover the following...
We'll cover the following...
Reading directories
Now that we’ve created a directory, we might wish to read one too. Indeed, that is exactly what the program ls does. Let’s write our own little tool like ls and see how it is done.
Instead of just opening a directory as if it were a file, we instead use a new set of calls. Below is an example program that prints the contents of a ...