地址:http://www.cnblogs.com/xudong-bupt/p/3504442.html
Linux C 读取文件夹下所有文件(包括子文件夹)的文件名
本文:http://www.cnblogs.com/xudong-bupt/p/3504442.html
Linux C 下面读取文件夹要用到结构体struct dirent,在头#include <dirent.h>中,如下:
#include <dirent.h> 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)等。
下面程序,递归读取某文件夹及其子文件夹下所有文件名:
按 Ctrl+C 复制代码
按 Ctrl+C 复制代码
执行输出 :
分类:
Linux下C编程