Use the opendir() function to open a directory in Linux. The opendir() function can open the specified directory and return a directory stream in the form of "DIR*". This return value must be used to read and search the specified directory; the syntax is "DIR * opendir(const char * name);" .
#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
linux opendir() function: open directory function
##1, header file:
#include <sys/types.h> #include <dirent.h>
2, define function
DIR * opendir(const char * name);
3, function description:
opendir() is used to open the directory specified by the parameter name, and return DIR * Directory stream in the form, similar to open(), this return value will be used for subsequent reading and searching of the directory.4, return value:
If successful, a directory stream of type DIR* will be returned. If the opening fails, NULL will be returned.5, error code:
6, Example:
#include <sys/types.h> #include <dirent.h> #include <stdio.h> int main() { int a = opendir("/etc/passwd"); printf("a = %d\n",a); return 0; }
Linux Video Tutorial》
The above is the detailed content of What function does Linux use to open a directory?. For more information, please follow other related articles on the PHP Chinese website!