1. opendir
DIR *opendir(const char *name);
DIR *fdopendir(int fd);
打开一个目录,失败返回空
2. readdir
struct dirent *readdir(DIR *dirp);
int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result);
读目录
struct dirent
{
ino_t d_ino; /* inode number 索引节点号*/
off_t d_off; /* offset to the next dirent 在目录文件中的偏移*/
unsigned short d_reclen; /* length of this record 文件名长*/
unsigned char d_type; /* type of file; not supported by all file system types 文件类型*/
char d_name[256]; /* filename 文件名,最长255字符*/
};
3. closedir
int closedir(DIR *dirp);
4. 举例
DIR *dir = opendir("./");
struct dirent *de;
if(dir)
{
while((de = readdir(dir)))
{
puts(de->d_name);
}
}
closedir(dir);