前两天写了一篇利用opencv中的Directory类实现文件夹遍历的博客(https://blog.csdn.net/weixin_42142612/article/details/82229420),但是昨晚在vs2013中用Directory类的方法就是出错.
同样的代码在VS2010中可以得到正常结果,但是VS2013中却不行,实在想不通..
没有找到解决VS2013中遍历问题的解决办法,只好另外想办法.然后想起C++中应该也有能够实现文件夹遍历的方法.
在VS2013中实践一下:
#include <stdio.h>
#include <io.h>
#include <string>
int main()
{
//目标文件夹路径
std::string inPath = "E:\\RuiJie\\VedioCapture\\2018-08-28 11-06-35\\*.jpg";//遍历文件夹下的所有.jpg文件
//用于查找的句柄
long handle;
struct _finddata_t fileinfo;
//第一次查找
handle = _findfirst(inPath.c_str(), &fileinfo);
if (handle == -1)
return -1;
do
{
//找到的文件的文件名
printf("%s\n", fileinfo.name);
} while (!_findnext(handle, &fileinfo));
_findclose(handle);
system("pause");
return 0;
}
可以遍历成功
参考博客:
https://blog.csdn.net/akadiao/article/details/79044390
http://qiaoxinwang.blog.163.com/blog/static/86096452010612139172/