首页 > 系统服务 > 详细

linux c遍历文件夹的方法

时间:2015-01-09 18:42:36      阅读:412      评论:0      收藏:0      [点我收藏+]

linux c遍历文件夹的方法比较简单,使用c来实现

 

 

#include <iostream>
#include <stdio.h>

#include <sys/types.h>
#include <dirent.h>
#include <sys/dir.h>
#include <sys/stat.h>

...
enum
{
    DT_UNKNOWN = 0,     //未知类型
    DT_FIFO = 1,        //管道
    DT_CHR = 2,         //字符设备文件
    DT_DIR = 4,         //目录
    DT_BLK = 6,         //块设备文件
    DT_REG = 8,         //普通文件
    DT_LNK = 10,        //连接文件
    DT_SOCK = 12,       //套接字类型
    DT_WHT = 14         //
};
void loopDir(const char *dir_path) { 
  char temp[256] = {0};
  struct dirent *pdirent;
DIR
*d_info = opendir(dir_path); if (d_info) { while ((pdirent = readdir(d_info)) != NULL) { if (pdirent->d_type & DT_REG) { //普通文件 } if (pdirent->d_type & DT_DIR) { //目录,递归 } } } } ...

 

linux c遍历文件夹的方法

原文:http://www.cnblogs.com/howeho/p/4213712.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!