Chinaunix首页 | 论坛 | 博客
  • 博客访问: 179392
  • 博文数量: 60
  • 博客积分: 1597
  • 博客等级: 上尉
  • 技术积分: 461
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-20 13:24
文章分类

全部博文(60)

文章存档

2017年(15)

2016年(6)

2015年(37)

2008年(2)

分类: C/C++

2016-01-22 16:31:10

   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;
}
阅读(1505) | 评论(0) | 转发(0) |
0

上一篇:图片比较

下一篇:ImageMaigck 压缩jpg图片

给主人留下些什么吧!~~