参考Demo下的VListView例子。以下代码从里面摘录。
procedure TForm1.CheckShellItems(StartIndex, EndIndex: Integer);
function ValidFileTime(FileTime: TFileTime): Boolean;
begin
Result := (FileTime.dwLowDateTime <> 0) or (FileTime.dwHighDateTime <> 0);
end;
var
FileData: TWin32FindData;
FileInfo: TSHFileInfo;
SysTime: TSystemTime;
I: Integer;
LocalFileTime: TFILETIME;
begin
//Here all the data that wasn't initialized in PopulateIDList is
//filled in.
for I := StartIndex to EndIndex do
begin
if ShellItem(I)^.Empty then
with ShellItem(I)^ do
begin
FullID := ConcatPIDLs(FPIDL, ID);
ImageIndex := GetShellImage(FullID, ListView.ViewStyle = vsIcon, False);
//File Type
SHGetFileInfo(
PChar(FullID),
0,
FileInfo,
SizeOf(FileInfo),
SHGFI_TYPENAME or SHGFI_PIDL
);
TypeName := FileInfo.szTypeName;
//Get File info from Windows
FillChar(FileData, SizeOf(FileData), #0);
SHGetDataFromIDList(
FIShellFolder,
ID,
SHGDFIL_FINDDATA,
@FileData,
SizeOf(FileData)
);
//File Size, in KB
Size := (FileData.nFileSizeLow + 1023 ) div 1024;
if Size = 0 then Size := 1;
//Modified Date
FillChar(LocalFileTime, SizeOf(TFileTime), #0);
with FileData do
if ValidFileTime(ftLastWriteTime)
and FileTimeToLocalFileTime(ftLastWriteTime, LocalFileTime)
and FileTimeToSystemTime(LocalFileTime, SysTime) then
try
ModDate := DateTimeToStr(SystemTimeToDateTime(SysTime))
except
on EConvertError do ModDate := '';
end
else
ModDate := '';
//Attributes
Attributes := FileData.dwFileAttributes;
//Flag this record as complete.
Empty := False;
end;
end;
end;
手上没有超过2G的文件存在,不能测试。但我想只要系统可以用文件属性显示出来,那么就可以API来读取出来,并不是一定要加载到内存才可以设置的。