backReading the directory


Hi!

I'd like to know how I can read a directory from my program.


opendir()/readdir()/closedir()

say info libc alpha opendir on the command line to get further information.


opendir

Syntax

     #include 

     extern int __opendir_flags;

     DIR *opendir(char *name);
Description
This function "opens" a directory so that you can read the list of file names in it. The pointer returned must be passed to `closedir' when you are done with it. *Note readdir::.

The global variable `__opendir_flags' can be set to include the following values to control the operation of `opendir':

`__OPENDIR_PRESERVE_CASE' Do not change the case of files to lower case. Just in case Micros*ft decides to support case-sensitive file systems some day.

`__OPENDIR_FIND_HIDDEN' Include hidden files and directories in the search. By default, these are skipped.

You can simply put "int __opendir_flags = ...;" in your code. The default is to let it get set to zero as an uninitialized variable.

Return Value
The open directory structure, or `NULL' on error.

Example

     DIR *d = opendir(".");
     closedir(d);
readdir
Syntax
     #include 

     struct dirent *readdir(DIR *dir);
Description
This function reads entries from a directory opened by `opendir' (*note opendir::.). It returns the information in a static buffer with this format:
     struct dirent {
       unsigned short d_namlen;  /* The length of the name */
       char d_name[MAXNAMLEN+1]; /* The name */
     };
Return Value
A pointer to a static buffer that is overridden with each call. Example
     DIR *d = opendir(".");
     struct dirent *de;
     while (de = readdir(d))
       puts(de->d_name);
     closedir(d);
closedir

Syntax

     #include 

     int closedir(DIR *dir);
Description
This function closes a directory opened by opendir (*note opendir::.). Return Value
Zero on success, nonzero if DIR is invalid.

strupr

Syntax

     #include 

     char *strupr(char *string);
Description
This function converts all lower case characters in STRING to upper case.