Directory functions

OK. First things first. These functions are NOT part of the ANSI standard library. They may not be supported on your platform.

Here is a quick summary of each function, they are listed in the order in which you may want to execute them.

  • opendir Open a directory stream.
  • readdir read the current entry in the stream.
  • scandir Find an entry in a direcory.
  • seekdir Jump to a directory offset.
  • telldir Return the current location within the directory stream.
  • rewinddir Return to the start of the directory stream.
  • closedir Close a directory.
      Library:   dirent.h
      Prototype: DIR *opendir(const char *name);
                 struct dirent *readdir(DIR *dir);
                 int scandir(const char *dir, struct dirent ***namelist,  
                     int (*select)(const struct dirent *),
                     int (*compar)(const void *, const void *));
    	     void seekdir(DIR *dir, off_t offset);
    	     off_t telldir(DIR *dir);
    	     void rewinddir(DIR *dir);
    	     int closedir(DIR *dir);
    The dirent structure does not seem to be documented in the man pages, so here it is.

    	struct dirent 
              long            d_ino;
           	  off_t           d_off;
           	  unsigned short  d_reclen;
           	  char            d_name[NAME_MAX+1];
    example program using opendir, readdir and closedir.

    See Also:

    stat function.

    man Pages:

    opendir readdir scandir seekdir telldir rewinddir closedir

    Top Master Index Keywords Functions

    Martin Leslie