C++/MFC-文件CFileFind

一、查找文件

 CFileFind类:

 例://c:\mydir\myfile.txt

GetFileName

获取文件名 myfile.txt

GetFilePath

获取文件路径c:\mydir\myfile.txt

GetFileTitle

获取文件标题 myfile

Close

关掉搜索请求,释放掉占用资源

 

FindFile

搜索目录,成功返回非零值,否则返回0

 

FindNextFile

继FindFile后查找下一个文件,最后一个文件时返回

 

 

IsReadOnly

Determines if the found file is read-only.

IsDirectory

Determines if the found file is a directory.

IsCompressed

Determines if the found file is compressed.

IsSystem

Determines if the found file is a system file.

IsHidden

Determines if the found file is hidden.

IsTemporary

Determines if the found file is temporary.

 

二、提取文件图标

WINSHELLAPIDWORD WINAPI SHGetFileInfo(
    LPCTSTR pszPath, //文件路径
    DWORD dwFileAttributes, //文件属性 忽略
    SHFILEINFO FAR *psfi,//返回文件信息
    UINT cbFileInfo, //SHFILEINFO 结构大小
    UINT uFlags //文件标志 SHGFI_ICON
);

三、示例代码

CListCtrl* plst_ctl = (CListCtrl*)GetDlgItem(IDC_LIST2);
//添加图标
m_imagelist_b.Create(32, 32, ILC_COLOR32 | ILC_MASK, 0, 0);
CFileFind findfile;
int nfound = findfile.FindFile(L"C:\\Windows\\//*.*");//C:\\Windows\\为Windows目录下的
int i = 0;
while (nfound)
{
	nfound = findfile.FindNextFileW();
	if (findfile.IsDirectory())
	{
		continue;
	}
	SHFILEINFO finfo;
	//获取文件信息,主要是图标icon
	SHGetFileInfo(findfile.GetFilePath(), 0, &finfo, sizeof(finfo), SHGFI_ICON);
		
	plst_ctl->InsertItem(i++, findfile.GetFileName(), m_imagelist_b.Add(finfo.hIcon));
		
}
plst_ctl->SetImageList(&m_imagelist_b, LVSIL_NORMAL);//大图标,若要小图标,则在定义一个CImageList变量,create、add
findfile.Close();//释放资源
 此处和 
 CImageList类、List Control控件结合起来使用。 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值