www.delorie.com/gnu/docs/glibc/libc_269.html   search  
Buy the book!

The GNU C Library

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

14.2 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 12. Input/Output on Streams.

14.2.1 Format of a Directory Entry  Format of one directory entry.
14.2.2 Opening a Directory Stream  How to open a directory stream.
14.2.3 Reading and Closing a Directory Stream  How to read directory entries from the stream.
14.2.4 Simple Program to List a Directory  A very simple directory listing program.
14.2.5 Random Access in a Directory Stream  Rereading part of the directory already read with the same stream.
14.2.6 Scanning the Content of a Directory  Get entries for user selected subset of contents in given directory.
14.2.7 Simple Program to List a Directory, Mark II  Revised version of the program.

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003