您当前的位置: 首页 >  c++

暂无认证

  • 1浏览

    0关注

    101061博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

C++实现读取指定文件夹下的所有文件

发布时间:2021-11-19 15:02:17 ,浏览量:1

前言

由于项目中需要读取某个文件夹的所有文件路径,这里简单总结如下,仅供备忘。

一 代码 1.1 头文件

include/algorithm.h

#include#include#includeusing namespace std;

#define linux
//#define _WIN32

vectorgetFilesList(string dirpath);

vectorgetFilesList(string dir);
1.2 cpp

src/algorithm.cpp

#include "algorithm.h"

#ifdef linux
#include 
#include 
vectorgetFilesList(string dirpath) {
	vectorallPath;
	DIR *dir = opendir(dirpath.c_str());
	if (dir == NULL)
	{
		cout << "opendir error" << endl;
		return allPath;
	}
	struct dirent *entry;
	while ((entry = readdir(dir)) != NULL)
	{
		if (entry->d_type == DT_DIR) {//It's dir
			if (strcmp(entry->d_nam
关注
打赏
1655516835
查看更多评论
立即登录/注册

微信扫码登录

0.4760s