int trave_dir(const char* path)
{
DIR *d; //声明一个句柄
struct dirent *file; //readdir函数的返回值就存放在这个结构体中
struct stat sb;
if (!(d = opendir(path))) {
printf("error opendir %s!!!\n", path);
return -1;
}else{
printf("\n\n\nstart read dir:%s\n",path);
}
while ((file = readdir(d)) != NULL) {
if (strncmp(file->d_name, ".", 1) == 0) {
continue;
}
string tmpFile=path;
tmpFile.append("/");
tmpFile.append(file->d_name);
stat(tmpFile.c_str(), &sb);
if((S_IFDIR & sb.st_mode)){
string subdir = path;
subdir += "/";
subdir += file->d_name;
trave_dir(subdir.c_str());
continue;
}
// filename tmpFile
}
closedir(d);
return 0;
}
阅读(1545) | 评论(0) | 转发(0) |