一、遍历文件夹下的文件
- DIR:文件夹的流对象(
目录信息结构体
),保存目录相关信息;
- struct dirent: 目录中的文件
dirent结构体可参见/usr/include/x86_64-linux-gnu/bits/dirent.h文件:
struct dirent
{
#ifndef __USE_FILE_OFFSET64
__ino_t d_ino;
__off_t d_off;
#else
__ino64_t d_ino;
__off64_t d_off;
#endif
unsigned short int d_reclen; //文件名长度
unsigned char d_type; //文件类型
char d_name[256]; //文件名
};
DIR *opendir (const char *__name); //根据名称打开目录流,并返回目录的DIR流
struct dirent *readdir (DIR *__dirp);//从DIR指定的对象中打开目录并读取目录中的条目(文件),并返回指向描述条目的结构体struct dirent的指针。
二、匹配字符
<fnmatch.h>