【原型】 DIR *opendir(constchar*name);
【功能】 打开目录以获得目录指针
【头文件】 #include <sys/types.h>#inlcude <dirent.h>
【参数】 name :目录名
【返回值】 成功: 目录指针 失败NULL
代码演示:
int n,n1;
DIR *dp =opendir("./abc");//打开一个文件也同时赋值了一个文件描述符
n =open("./abc/2.txt",O_RDWR);//打开这个文件夹里的一个文件,则文件描述符为4printf("%d\n",n);close(n);closedir(dp);
n =open("./abc/2.txt",O_RDWR);//现在关闭了文件夹abc,则里面的文件描述符为3printf("%d\n",n);close(n);