结构体:
DIR 类似于FILE
dirent
- struct dirent
- {
- long d_ino; /* inode number 索引节点号 */
- off_t d_off; /* offset to this dirent 在目录文件中的偏移 */
- unsigned short d_reclen; /* length of this d_name 文件名长 */
- unsigned char d_type; /* the type of d_name 文件类型 */
- char d_name [NAME_MAX+1]; /* file name (null-terminated) 文件名,最长255字符 */
- }
函数:
DIR * = opendir("PATH")
dirent * = readdir(DIR*)
例子:(/var/tmp 下有a,b,c,d四个文件)
#include(dirent.h)
DIR *dir;
dirent * tmp;
dir = opendir("/var/tmp");
while((tmp = readdir(dir))!=NULL)
{
printf("%s\n",dir->d_name);
}