[code]
通过 io.h中的 _findfirst函数 和 _findnext函数可以实现 目录和文件的遍历。但是如果我们想
让文件和目录区分开,并在目录旁标识出又该怎样做呢?
int handledir(const char* filepath,int flag)
{
struct _finddata_t t;
intptr_t a;
intptr_t n = 0,b;
if(flag){
char buf[] = "\\*.*";
char path[_MAX_PATH];
strcpy(path,filepath);
strcat(path,buf);
a = _findfirst(path,&t);
}else{
a = _findfirst(filepath,&t);
}
do{
//handledir(t.name);
printf("%s\n",t.name);
b = _findnext(a,&t);
}while(b>=0);
_findclose(a);
return 1;
}[/code]