函数名: findfirst, findnext
功 能: 搜索磁盘目录; 取得下一个匹配的findfirst模式的文件
用 法: int findfirst(char *pathname, struct ffblk *ffblk, int attrib);
int findnext(struct ffblk *ffblk);
程序例:
/* findnext example */
#include <stdio.h>
#include <dir.h>
//两个函数需要定义一个结构体来存储函数返回的数据。结构体如下:
struct ffblk
{
char ff_reserved[21]; /*DOS保留字*/
char ff_attrib; /*文件属性*/
int ff_ftime; /*文件时间*/
int ff_fdate; /*文件日期*/
long ff_fsize; /*文件长度*/
char ff_name[13]; /*文件名*/
}
//将结构体中的ff_name[13]显示出来即可。
int main(void)
{
struct ffblk ffblk;
int done;
printf("Directory listing of *.*
");
done = findfirst("*.*",&ffblk,0);
while (!done)
{
printf(" %s
", ffblk.ff_name);
done = findnext(&ffblk);
}
return 0;
}