microsoftxiao

记忆 流逝

导航

遍历文件和目录C

[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]

posted on 2006-03-06 16:17  龙巢NET刀  阅读(358)  评论(0)    收藏  举报