Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/o/opendir.html on line 1
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/o/opendir.html on line 1
Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/o/opendir.html on line 8
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/o/opendir.html on line 8
Open a directory
#include <dirent.h>
DIR * opendir( const char * dirname );
- dirname
- The path of the directory to be opened.
It can be relative to the current working directory, or an absolute path.
libc
Use the -l c option to
qcc
to link against this library.
This library is usually included automatically.
The opendir() function is used with
readdir() and
closedir() to get the
list of file names contained in the directory specified by
dirname.
You can read more than one directory at the same time using the
opendir(),
readdir(),
rewinddir()
and
closedir()
functions.
|
The result of using a directory stream after one of the exec*()
or spawn*() functions is undefined. After a call to
the fork()
function, either the parent or the child (but not both) can continue
processing the directory stream using readdir() and
rewinddir().
If both the parent and child processes use these functions, the result
is undefined. Either process can use closedir().
|
A pointer to a DIR structure required for subsequent calls to
readdir() to retrieve the file names in dirname, or
NULL if dirname isn't a valid path (errno
is set).
- EACCES
- Search permission is denied for a component of dirname,
or read permission is denied for dirname.
- ELOOP
- Too many levels of symbolic links or prefixes.
- ENAMETOOLONG
- The length of dirname exceeds
PATH_MAX, or a pathname component is longer than
NAME_MAX.
- ENOENT
- The named directory doesn't exist.
- ENOSYS
- The opendir() function isn't implemented for the filesystem specified
in dirname.
- ENOTDIR
- A component of dirname isn't a directory.
Get a list of files contained in the directory
/home/fred:
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
int main( void )
{
DIR* dirp;
struct dirent* direntp;
dirp = opendir( "/home/fred" );
if( dirp == NULL ) {
perror( "can't open /home/fred" );
} else {
for(;;) {
direntp = readdir( dirp );
if( direntp == NULL ) break;
printf( "%s\n", direntp->d_name );
}
closedir( dirp );
}
return EXIT_SUCCESS;
}
POSIX 1003.1
Safety: | |
Cancellation point |
Yes |
Interrupt handler |
No |
Signal handler |
No |
Thread |
Yes |
closedir(),
dirent,
errno,
readdir(),
readdir_r(),
rewinddir(),
seekdir(),
telldir()
Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/o/opendir.html on line 225
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/o/opendir.html on line 225