GNU Info

Info Node: (libc.info)Accessing Directories

(libc.info)Accessing Directories


Next: Working with Directory Trees Prev: Working Directory Up: File System Interface
Enter node , (file) or (file)node

Accessing Directories
=====================

   The facilities described in this section let you read the contents
of a directory file.  This is useful if you want your program to list
all the files in a directory, perhaps as part of a menu.

   The `opendir' function opens a "directory stream" whose elements are
directory entries.  You use the `readdir' function on the directory
stream to retrieve these entries, represented as `struct dirent'
objects.  The name of the file for each entry is stored in the `d_name'
member of this structure.  There are obvious parallels here to the
stream facilities for ordinary files, described in Note: I/O on
Streams.

Directory Entries
Format of one directory entry.
Opening a Directory
How to open a directory stream.
Reading/Closing Directory
How to read directory entries from the stream.
Simple Directory Lister
A very simple directory listing program.
Random Access Directory
Rereading part of the directory
already read with the same stream.
Scanning Directory Content
Get entries for user selected subset of
contents in given directory.
Simple Directory Lister Mark II
Revised version of the program.

automatically generated by info2www version 1.2.2.9