没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
深入探讨深入探讨:linux中遍历文件夹下的所有文件中遍历文件夹下的所有文件
本篇文章是对linux中遍历文件夹下的所有文件进行了详细的分析介绍,需要的朋友参考下
linux C 遍历目录及其子目录遍历目录及其子目录
复制代码 代码如下:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dirent.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/types.h>
using namespace std;
void listDir(char *path)
{
DIR *pDir ;
struct dirent *ent ;
int i=0 ;
char childpath[512];
pDir=opendir(path);
memset(childpath,0,sizeof(childpath));
while((ent=readdir(pDir))!=NULL)
{
if(ent->d_type & DT_DIR)
{
if(strcmp(ent->d_name,".")==0 || strcmp(ent->d_name,"..")==0)
continue;
sprintf(childpath,"%s/%s",path,ent->d_name);
printf("path:%s/n",childpath);
listDir(childpath);
}
else
{
cout<<ent->d_name<<endl;
}
}
}
int main(int argc,char *argv[])
{
listDir(argv[1]);
return 0;
}
Linux C :遍历输出指定目录下的所有文件:遍历输出指定目录下的所有文件
在Linux下opendir()、、readdir()和和closedir()这三个函数主要用来遍历目录。在使用这三个函数前必须先包括以下两个头文须先包括以下两个头文
件:件:
#include <sys/types.h>
#include <dirent.h>
opendir函数的原型为:
DIR *opendir(const char *name);
它返回一个DIR*类型,这就是一个句柄啦,你不用管它的内部结构是什么样的,只要知道这个句柄就是等一下要传给readdir()
函数的参数就行了。
readdir函数的原型为:函数的原型为:
struct dirent *readdir(DIR *dir);
看它的参数就知道该参数是opendir函数返回的句柄,而该函数的返回值是struct dirent* 类型,这里我们必须了解一下这个结
资源评论
weixin_38656395
- 粉丝: 4
- 资源: 912
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- python语言解决背包问题,使用递归和动态规划两种思路并比较运行速度
- 基于Django和Celery的中国知网(CNKI)爬虫及数据可视化设计源码
- 基于C++实现的斐波那契数列
- 基于SSM框架的Java家庭财务管理设计源码
- UDP转发脚本udp-forwarding-udp-forward-master.zip
- tio来开发udptio-udp-showcase-master.zip
- 基于Scala的Spark数字仓库推荐系统设计源码
- 基于Django的博客系统设计源码
- 基于Node.js和AngularJS的JsGen社区网站系统设计源码
- 基于Vue和Echarts的数据可视化大屏设计源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功