获取创建日期
使用 IShellItem2
IShellItem2 扩展了IShellItem,添加了许多帮助方法来从属性系统中检索类型化的属性。
var
ft: FILETIME;
createdDate: TDateTime;
// IShellItem2 provides many handy helper methods to IShellItem
(shellItem as IShellItem2).GetFileTime(PKEY_DateCreated, {out}ft);
createdDate := FileTimeToDateTime(ft);
使用 IShellItem
Windows Vista Windows XP1 添加了IShellItem,将[IShellFolder]+[ITEMID_CHILD] 封装成一个对象。 Windows Vista 增加了丰富的属性系统,IPropertyStore 是一组键值对属性(包括PKEY_DateCreated):
var
ps: IPropertyStore;
pv: TPropVariant;
ft: FILETIME;
createdDate: TDateTime;
//Get the IPropertyStore yourself, in order to read the property you want
shellItem.BindToHandler(nil, BHID_PropertyStore, IPropertyStore, {out}ps);
ps.GetValue(PKEY_DateCreated, {out}pv);
PropVariantToFileTime(pv, PSTF_UTC, {out}ft);
createdDate := FileTimeToDateTime(ft);
使用 IShellFolder
IShellFolder 是原来的 Windows 95 界面。它仅代表一个文件夹,您必须询问该文件夹中的项目(ITEMID_CHILD)。 Vista之前没有PKEY_DateCreated,因为属性系统直到 Vista才存在。但文件和文件夹仍然有 CreationTime
var
folder: IShellFolder;
parent: PIDLIST_ABSOLUTE;
child: PITEMID_CHILD;
findData: WIN32_FIND_DATA;
// We have an IShellItem that represents IShellFolder+ChildItemID.
// Ask the IShellItem to cough up its IShellFolder and child pidl
(shellItem as IParentAndItem).GetParentAndItem(parent, folder, child);
// Get the WIN32_FIND_DATA information associated with the child file/folder
SHGetDataFromIDList(folder, child, SHGDFIL_FINDDATA, findData, sizeof(findData));
createdDate := FileTimeToDateTime(findData.ftCreationTime);