从文件夹下连续读取所有图片 VS2010

来源:互联网 发布:淘宝店铺私信号怎么加 编辑:程序博客网 时间:2024/05/01 07:57

关键点:

到指定文件夹读取所有文件的名字;

将文件名转换为对应的Path名。


源代码:

#include <stdlib.h>#include <stdio.h>#include <fstream>#include <string>#include <tchar.h>#include <afx.h>#include <iostream>using namespace std; int main(){   CFileFind finder;    CString strFileName;   BOOL bResult = FALSE;   BOOL bWorking = finder.FindFile(_T("D:\\images\\*.jpg"));//过滤字符串,*.*是所有文件   while(bWorking)   {     bWorking = finder.FindNextFile();     if (finder.IsDots())     {        continue;     } if(!finder.IsDirectory())      {         CString absolutePath=finder.GetFilePath();         TCHAR *p =absolutePath.GetBuffer();        int iSize;         char* name;         //进行类型转换,主要是Unicode到ANSI        iSize = WideCharToMultiByte(CP_ACP, 0, p, -1, NULL, 0,NULL, NULL);         name = (char*)malloc((iSize+1));        WideCharToMultiByte(CP_ACP, 0, p, -1, name, iSize, NULL, NULL);         printf("%s\n",name);//输出文件名     }    }   system("pause");}
实验结果:



参考链接:

[1]http://www.opencv.org.cn/forum/viewtopic.php?f=1&t=9972

[2]http://www.opencvchina.com/thread-332-1-1.html