win10 下 c++遍历文件夹

主要使用#include <io.h>库下的函数


如果 路劲句柄定义为long类型,_findnext函数会报 访问异常,解决方法参考:http://blog.csdn.net/kelvin_yan/article/details/53997840


实例代码:

#include <fstream>
#include <string>
#include "utils.h"
#include <stdio.h>

#include <direct.h>
#include <iostream>
#include <io.h>

using namespace std;
using namespace cv;

string trainPtah = "F://vido and images fro test//UIUC texture database";

void getClassName(string path, vector<string>& paths)
{
	intptr_t hFile = 0;
	struct _finddata_t fileinfo;
	string p;

	hFile = _findfirst(p.assign(path).append("\\*").c_str(), &fileinfo);

	if (hFile != -1) {
		while (_findnext(hFile, &fileinfo) == 0) {
			if (fileinfo.attrib & _A_SUBDIR) {
				if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0) {
					paths.push_back(p.assign(path).append("/").append(fileinfo.name));//保存文件夹名字
				}
			}
		}
	}
}


void main()
{
	vector<string> paths;
	getClassName(trainPtah, paths);
	for (int i = 0; i < paths.size(); i++) {
		cout << paths.at(i) << endl;
	}

	system("pause");
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值