(Gast)
n/a Beiträge
|
AW: Dateigröße ermitteln, wie geht Ihr vor?
26. Jan 2018, 00:06
danke für deinen vorschlag, ich versuche das was jetzt kommt in eine delphi ide vcl variante umzubauen,
das liest ein verzeichniss ein und gibt dateien in eine ListView mit icon und paar info's wieder.
Delphi-Quellcode:
procedure GetFiles(const hLV: HWND; Path, Mask: String);
var
finddata : TWin32FindData;
hFile : cardinal;
Loop : dword;
lvi : TLVItem;
buf : array[0..25]of char;
tile : TLVTileInfo;
fi : TSHFileInfo;
LVIMark : TLVInsertMark;
tmp : String;
i : integer;
begin
hFile := FindFirstFile(PChar(IncludeTrailingPathDelimiter(Path) + Mask), finddata);
if(hFile <> INVALID_HANDLE_VALUE) then begin
LockWindowUpdate(hDlg);
LastFolder := IncludeTrailingPathDelimiter(Path);
Loop := 0;
repeat
if(finddata.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY = 0) then begin
ZeroMemory(@fi, sizeof(TSHFileInfo));
ListView_SetImageList(hLV,
SHGetFileInfo(PChar(IncludeTrailingPathDelimiter(Path) + finddata.cFilename), 0,
fi, sizeof(TSHFileInfo), SHGFI_SYSICONINDEX or SHGFI_TYPENAME or SHGFI_SMALLICON), LVSIL_SMALL);
ZeroMemory(@fi, sizeof(TSHFileInfo));
ListView_SetImageList(hLV,
SHGetFileInfo(PChar(IncludeTrailingPathDelimiter(Path) + finddata.cFilename), 0,
fi, sizeof(TSHFileInfo), SHGFI_SYSICONINDEX or SHGFI_TYPENAME or SHGFI_ICON), LVSIL_NORMAL);
lvi.mask := LVIF_TEXT or LVIF_IMAGE;
lvi.iItem := Loop;
lvi.iSubItem := 0;
lvi.pszText := finddata.cFileName;
i := 0;
lvi.iImage := fi.iIcon;
ListView_InsertItem(hLV, lvi);
tmp := IntToStr(finddata.nFileSizeLow)+' byte';
if (finddata.nFileSizeLow / 1024) > 1 then tmp := FloatToStr((finddata.nFileSizeLow / 1024),-1,2)+' kb';
if (finddata.nFileSizeLow / 1024 / 1024) > 1 then tmp := FloatToStr((finddata.nFileSizeLow / 1024 / 1024),-1,2)+' mb';
if (finddata.nFileSizeLow / 1024 / 1024 / 1024) > 1 then tmp := FloatToStr((finddata.nFileSizeLow / 1024 / 1024 / 1024),-1,2)+' gb';
lvi.mask := LVIF_TEXT;
lvi.iSubItem := 1;
lvi.pszText := pChar(tmp);
ListView_SetItem(hLV, lvi);
lvi.mask := LVIF_TEXT;
lvi.iSubItem := 2;
lvi.pszText := fi.szTypeName;
ListView_SetItem(hLV, lvi);
// ZeroMemory(@buf, sizeof(buf));
// wvsprintf (buf, '%u byte', pchar(@finddata.nFileSizeLow));
lvi.mask := LVIF_TEXT;
lvi.iSubItem := 3;
lvi.pszText := pChar(IntToStr(finddata.nFileSizeLow)); //buf;
ListView_SetItem(hLV, lvi);
if GetOSVersion = osXP then begin
tile.cbSize := sizeof(TLVTileInfo);
tile.iItem := Loop;
// tile.cColumns := length(colArray);
tile.puColumns := @colArray[0];
ListView_SetTileInfo(hLV, tile);
end;
LVIMark.cbSize := sizeof(TLVInsertMark);
LVIMark.dwFlags := LVIM_AFTER;
LVIMark.iItem := Loop;
LVIMark.dwReserved := 0;
ListView_SetInsertMark(hLV, LVIMark);
if LowerCase(ExtractFileName(SelectedFile)) = LowerCase(finddata.cFileName) then
begin
{ if LowerCase(ExtractFileName(SelectedFile)) = LowerCase(finddata.cFileName) then
ListView_SetItemState(hLV, Loop, 0, LVIS_SELECTED);}
lvi.stateMask := LVIS_SELECTED;
lvi.state := LVIS_SELECTED;
SendMessage(hLV, LVM_SETITEMSTATE, Loop, Longint(@lvi))
end;
Inc(Loop);
end;
until (not FindNextFile(hFile, finddata));
FindClose(hFile);
LockWindowUpdate(0);
end;
end;
vielleicht kann man das auch "tunen" ?
Grüße
|
|
Zitat
|