从ITEMIDLIST(pidl)中检索文件大小的更快方法



我看到了一堆示例来显示类似资源管理器的视图。就像PJ Naughter的这个http://www.naughter.com/shellctrls2.html

问题总是出在速度上。

瓶颈是对文件大小的评估。这是通过一个额外的调用来获得文件状态(上次更改日期和文件大小(。

case static_cast<int>(Columns::SizeColumn): //deliberate fallthrough
case static_cast<int>(Columns::DateModifiedColumn):
{
CString sPath;
CFileStatus fs;
if (pItem->m_pidlFQ.ToPath(sPath) && CFile::GetStatus(sPath, fs))
{
CString sText;
if (nColumn == static_cast<int>(Columns::SizeColumn))
{
if ((fs.m_attribute & (CFile::directory | CFile::volume)) == 0)
OnFormatFileSize(fs.m_size, sText);
}
else
OnFormatFileDate(fs.m_mtime, sText);
return sText;
}
break;
}

但这是缓慢的。有没有一种更简单的方法,直接从pidl中获取修改日期和文件大小?

是的,大小和日期99%的时间都缓存在pidl中,您不必询问文件系统。您决不能将pidl转换为路径,而是使用shell API。

如果您只关心Vista和更高版本,则可以使用SHCreateItemFromIDList+IShellItem2::GetUInt64 (PKEY_Size, &size),否则必须使用SHBindToParent+IShellFolder2::GetDetailsEx

最新更新