Linux C 下面读取文件夹要用到结构体struct dirent,在头#include 中,如下:
#include
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字符 */
}
其中d_type表明该文件的类型:文件(8)、目录(4)、链接文件(10)等。
下面程序,递归读取某文件夹及其子文件夹下所有文件名: