MFC对话框,怎样获取指定目录的所有图片路径 大家好,我是用VS2005 MFC对话框开发的,我想请问一下怎么获取指定目录的所有图片路径!因为我要导入指定文件夹的所有图片!最好能给个简单的例子,非常感谢!如: D:\images里有 a.bmp b.bmp, c.jpeg, d.png 还有 path.txt 等其他非图片文件我现在只是想要 所有图片 的路径,谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 CFileFindCObject └CFileFind MFC类CFileFind执行本地文件查找,是CGopherFileFind和CFtpFileFind的基类;后两类用于Internet文件查找。CFileFind包括的成员函数有开始查找、定位文件、返回标题名或路径。对于Internet查找来说,GetFileURL返回文件的URL。CFileFind是为另两类查找特殊服务器设计的MFC类的基类,CGopherFileFind在Gopher服务器上工作,CFtpFileFind在FTP服务器上工作,这些类为用户查找文件提供了一种无缝机制,与服务器协议、文件类型、地点、本地机器或远程服务器无关。以下代码将当前目录下的文件枚举出来并打印每个文件名:CFileFind finderBOOL bWorking = finder.FindFile("*.*");while(bWorking){ bWorking = finder.FindNextFile( ); cout <<(LPCTSTR) finder.GetFileName( ) <<endl;}为使示例简单,此代码使用标准C++库函数cout类,cout行可由调用CListBox::AddString来代替。要了解有关CFileFind和其它WinInet类共同使用的情况,请参阅联机文档“Visual C++程序员指南”中的“用WinInet设计Internet程序”。#include <afx.h>请参阅:CFtpFileFind, CGopherFileFind, CInternetFile, CGopherFile, CHttpFileCFileFind类的成员构造函数 CFileFind 构造一个CFileFind对象。 属性 GetLength 获取找到文件的长度,以字节为单位 GetFileName 获取找到文件的名字 GetFilePath 找到文件的全路径 GetFileTitle 获取找到文件的标题,标题不包括扩展内容 GetFileURL 获取找到文件的URL,包括文件路径 GetRoot 获取找到文件根目录 GetCreationTime 获取文件创建时间 GetLastAccessTime 获取文件最后一次打开的时间 GetLastWriteTime 文件最后改变和存储的时间 MatchesMask 指定要找的文件的属性 IsDots 查看文件名是否是包含"."或"..",以表明它的确是一个目录 IsReadOnly 文件是否是只读 IsDirectory 文件是否是目录 IsCompressed 文件是否是压缩 IsSystem 文件是否是系统文件 IsHidden 文件是否是隐藏 IsTemporary 文件是否是临时的 IsNormal 文件是否是常规的(无其它属性) IsArchived 文件是否是档案 操作Close 关闭查找请求 FindFile 查找一个目录中的指定文件 FindNextFile 从FindFile以前调用开始继续下一查找 CFileFind类 搜索文件对搜索到的文件进行操作 void RecurseFile(CString strPath){ CFileFind Filefinder; strDir+=_T("\\*.*"); BOOL bWorking=Filefinder.FindFile(strDir); while(bWorking) { bWorking=Filefinder.FindNextFile(); if (Filefinder.IsDots()) continue; if (Filefinder.IsDirectory()) continue; if (Filefinder.IsArchived()) { CString strPath=Filefinder.GetName() if(strPath.ReverseFind('.jpg')!=NULL ||strPath.ReverseFind('.png')!=NULL ||strPath.ReverseFind('.bmp')!=NULL) { //找到图片文件 进行操作 } RecurseDir(strPath); } } Filefinder.Close();}临时写的 仅作为参考 CArray<CString,CString> CFaceRecognitionDlg::GetScrPath(CString dir){ CFileFind finder; CString strPath; BOOL bWorking = finder.FindFile(dir); CArray<CString,CString> paths; while (bWorking) { bWorking = finder.FindNextFile(); strPath=finder.GetFilePath(); paths.Add (strPath); } finder.Close (); return paths;}我这样写,怎么就报错了! 错误为: 'CObject::CObject' : cannot access private member declared in class 'CObject' RecurseDir(strPath);//这个是什么东西来的啊? 怎么改变控件上的字体大小? 急!如何用MCI命令播放ASF? 【广告】上海构件库网站正式发布,欢迎广大软件开发者及相关人士! 请教:对this指针有点疑惑 如何获取系统当前的显示分辨率和颜色设置? 在VC中如何嵌入AT命令的代码?马上送分 capDriverConnect函数和capDriveDisconnect函数疑问 CArray 的困惑之一 热键注册问题 怎样得到RichEditView中光标的行列位置? vc9编译的控制台程序,XP下无法运行 有关链表的问题
└CFileFind MFC类CFileFind执行本地文件查找,是CGopherFileFind和CFtpFileFind的基类;后两类用于Internet文件查找。CFileFind包括的成员函数有开始查找、定位文件、返回标题名或路径。对于Internet查找来说,GetFileURL返回文件的URL。
CFileFind是为另两类查找特殊服务器设计的MFC类的基类,CGopherFileFind在Gopher服务器上工作,CFtpFileFind在FTP服务器上工作,这些类为用户查找文件提供了一种无缝机制,与服务器协议、文件类型、地点、本地机器或远程服务器无关。
以下代码将当前目录下的文件枚举出来并打印每个文件名:
CFileFind finder
BOOL bWorking = finder.FindFile("*.*");
while(bWorking)
{
bWorking = finder.FindNextFile( );
cout <<(LPCTSTR) finder.GetFileName( ) <<endl;
}
为使示例简单,此代码使用标准C++库函数cout类,cout行可由调用CListBox::AddString来代替。
要了解有关CFileFind和其它WinInet类共同使用的情况,请参阅联机文档“Visual C++程序员指南”中的“用WinInet设计Internet程序”。
#include <afx.h>请参阅:
CFtpFileFind, CGopherFileFind, CInternetFile, CGopherFile, CHttpFileCFileFind类的成员构造函数
CFileFind 构造一个CFileFind对象。 属性
GetLength 获取找到文件的长度,以字节为单位
GetFileName 获取找到文件的名字
GetFilePath 找到文件的全路径
GetFileTitle 获取找到文件的标题,标题不包括扩展内容
GetFileURL 获取找到文件的URL,包括文件路径
GetRoot 获取找到文件根目录
GetCreationTime 获取文件创建时间
GetLastAccessTime 获取文件最后一次打开的时间
GetLastWriteTime 文件最后改变和存储的时间
MatchesMask 指定要找的文件的属性
IsDots 查看文件名是否是包含"."或"..",以表明它的确是一个目录
IsReadOnly 文件是否是只读
IsDirectory 文件是否是目录
IsCompressed 文件是否是压缩
IsSystem 文件是否是系统文件
IsHidden 文件是否是隐藏
IsTemporary 文件是否是临时的
IsNormal 文件是否是常规的(无其它属性)
IsArchived 文件是否是档案 操作
Close 关闭查找请求
FindFile 查找一个目录中的指定文件
FindNextFile 从FindFile以前调用开始继续下一查找
对搜索到的文件进行操作
void RecurseFile(CString strPath)
{
CFileFind Filefinder;
strDir+=_T("\\*.*");
BOOL bWorking=Filefinder.FindFile(strDir);
while(bWorking)
{
bWorking=Filefinder.FindNextFile();
if (Filefinder.IsDots())
continue;
if (Filefinder.IsDirectory())
continue;
if (Filefinder.IsArchived())
{
CString strPath=Filefinder.GetName()
if(strPath.ReverseFind('.jpg')!=NULL
||strPath.ReverseFind('.png')!=NULL
||strPath.ReverseFind('.bmp')!=NULL)
{
//找到图片文件 进行操作
}
RecurseDir(strPath);
}
}
Filefinder.Close();
}
临时写的 仅作为参考
{
CFileFind finder;
CString strPath;
BOOL bWorking = finder.FindFile(dir);
CArray<CString,CString> paths;
while (bWorking)
{
bWorking = finder.FindNextFile();
strPath=finder.GetFilePath();
paths.Add (strPath);
}
finder.Close ();
return paths;
}我这样写,怎么就报错了!
'CObject::CObject' : cannot access private member declared in class 'CObject'