1. 前言
之前用_finddata_t结构体做的C++文件夹遍历程序在Win10 VS2015环境下不能使用了,找了半天没找到原因,突然在网上看到使用Opencv也可以实现文件夹遍历的功能,这里对其进行了总结,主要分为3.0之前的版本和之后的版本。
2. Opencv 2X实现
在Opencv 2X的版本中包含了contrib模块,其里面封装了一个Directory
类,用该类就可以实现对于目录的遍历操作,在该内部包含了三个成员函数:
1)GetListFiles:遍历指定文件夹下的所有文件,不包括指定文件夹内的文件夹;
2)GetListFolders:遍历指定文件夹下的所有文件夹,不包括指定文件夹下的文件;
3)GetListFilesR:遍历指定文件夹下的所有文件,包括指定文件夹内的文件夹。
class CV_EXPORTS Directory
{
public:
static std::vector<std::string> GetListFiles(const std::string& path, const std::string & exten = "*", bool addPath = true);
static std::vector<std::string> GetListFilesR(const std::string& path, const std::string & exten =