glibc 递归遍历文件夹 dfs_search_file
来源:互联网 发布:mac照片找不到 编辑:程序博客网 时间:2024/06/06 01:22
dfs_search_file
#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <sys/stat.h>#include <dirent.h>#include <string.h>int dfs_search_file (const char *dir){ DIR *dp; struct dirent *ep; struct stat statbuf; dp = opendir (dir); if (dp != NULL) { while ((ep = readdir (dp))!=NULL) { if(ep->d_type==4) {//is dir if (strcmp(ep->d_name , ".")==0 || strcmp(ep->d_name , "..")==0) //if (ep->d_name[strlen(ep->d_name)-1]=='.') { continue; } // char * tmp = (char *)malloc(sizeof(char) * (strlen(ep->d_name) + strlen(dir)+2 )); strcpy(tmp,dir); strcat(tmp,"/"); strcat(tmp,ep->d_name); // //puts (ep->d_name); dfs_search_file(tmp); free(tmp); } else if(ep->d_type==8) { char * tmp = (char *)malloc(sizeof(char) * (strlen(ep->d_name) + strlen(dir)+2 )); strcpy(tmp,dir); strcat(tmp,"/"); strcat(tmp,ep->d_name); printf("%s\n", tmp); free(tmp); } } (void) closedir (dp); } else { perror ("Couldn't open the directory"); } return 0;}int main(int argc, char const *argv[]){dfs_search_file("/home");return 0;}
1 0
- glibc 递归遍历文件夹 dfs_search_file
- 使用递归遍历文件夹
- 递归法遍历文件夹
- VBS递归遍历文件夹
- 非递归遍历文件夹
- 非递归遍历文件夹
- 递归遍历文件(文件夹)
- java 递归遍历文件夹
- 非递归遍历文件夹
- 文件夹递归遍历
- php递归遍历文件夹
- 非递归遍历文件夹
- 递归遍历文件夹脚本
- as3 递归 遍历文件夹
- 深度递归遍历文件夹
- JAVA递归遍历文件夹
- boost递归遍历文件夹
- C#递归遍历文件夹
- 产品细节设计:纠正你的网站注册时[验证邮箱]的流程
- 安卓图片优化之Bitmap优化(一)
- iOS事件传递及响应者关系链
- Androd 实现投票的功能(问卷调查)
- 10实践项目1
- glibc 递归遍历文件夹 dfs_search_file
- Python note (one)
- Hive分区表修改表结构的问题
- AndroidStudio导入项目一直Building解决方案
- Unity Shader Example 25 (在ShaderLab Surface 添加顶点颜色与透明效果)
- Git教程
- js瀑布流,简单封装
- android 按钮点击的两种方法以及长按事件
- 博客