首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

linux C语言上遍历文件夹的有关问题,望大侠解决,多谢!

2012-08-03 
linux C语言下遍历文件夹的问题,望大侠解决,谢谢!!!!!!!小弟在linux下使用gcc编译时出现点问题, 望大侠给

linux C语言下遍历文件夹的问题,望大侠解决,谢谢!!!!!!!
小弟在linux下使用gcc编译时出现点问题, 望大侠给解:
#include <sys/types.h>

#include <sys/stat.h>

#include <dirent.h>

#include <pwd.h>

#include <unistd.h>

#include <stdio.h>




//struct dirent中的几个成员:

//d_type:4表示为目录,8表示为文件

//d_reclen:16表示子目录或文件,24表示非子目录

//d_name:目录或文件的名称

int main(int argc, char *argv[])
{
List(argv[1]);
return 0;
}

void List(char *path)
{
struct dirent* ent = NULL;
DIR *pDir;
pDir=opendir(path);
while (NULL != (ent=readdir(pDir)))
{
if (ent->reclen==24)
{
if (ent->d_type==8)
printf("%s\n", ent->d_name);
else
{
printf("子目录:%s\n",ent->d_name);
List(ent->d_name);
printf("返回%s\n",ent->d_name);
}
}
}
}


错误提示: 方法“List” 起冲突,希望朋友能帮帮忙,感激!!!


[解决办法]

C/C++ code
#include <sys/types.h>#include <sys/stat.h>#include <dirent.h>#include <pwd.h>#include <unistd.h>#include <stdio.h>//struct dirent中的几个成员://d_type:4表示为目录,8表示为文件//d_reclen:16表示子目录或文件,24表示非子目录//d_name:目录或文件的名称[color=#FF6600]void List(char *);     //List使用之前应该声明[/color];int main(int argc, char *argv[]){List(argv[1]);return 0;}void List(char *path){struct dirent* ent = NULL;DIR *pDir;pDir=opendir(path);while (NULL != (ent=readdir(pDir))){[color=#FF6600]if (ent->d_reclen==24)  // d_reclen 不是reclen[/color]{if (ent->d_type==8)printf("%s\n", ent->d_name);else{printf("子目录:%s\n",ent->d_name);List(ent->d_name);printf("返回%s\n",ent->d_name);}}}}
[解决办法]
把list重新命名为MyList试试
[解决办法]
C/C++ code
在main前面加上void List(char *path); 

热点排行
Bad Request.