Hy @ all,
ich hab mal wieder ein Problem
Und zwar möchte ich gern alle Dateien eines Unterverzeichnisses in einem TListview (ListView3) darstellen.
Listview3:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36:
| object ListView3: TListView Left = 14 Top = 400 Width = 595 Height = 264 Color = clNone Columns = < item Caption = 'Name' Width = 320 end item Caption = 'Erw' Width = 40 end item Caption = 'Gr'#246#223'e' Width = 41 end item Caption = 'Datum' Width = 100 end item Caption = 'Attr' Width = 70 end> Ctl3D = False GridLines = True ReadOnly = True RowSelect = True SmallImages = ImageList2 TabOrder = 8 ViewStyle = vsReport OnDblClick = ListView3DblClick |
Bei FormCreate passiert folgendes:
Delphi-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
| uses ShellApi;
procedure TForm1.FormCreate(Sender: TObject); var path: string; begin GetDir(0,path); path:=path+'\'; Verzeichnisbaumsteuern(path); end; |
Verzeichnisbaumsteuern ist so aufgebaut (teilweise von den Schweizern abgeguggt

)
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119:
| procedure TForm1.Verzeichnisbaumsteuern(path: string); var SR: TSearchRec; F: TSearchRec; size: Int64; i,e, g,h: integer; hFile: THandle; rStructur: TWin32FindData; rFileTime: TFileTime; dwLastAccess: cardinal; date1: TDate; aFileName,erw,name,drueber: string; Info: TSHFileInfo; ListItem:TListItem; punkt: boolean; begin label17.Caption:=path; Listview3.Clear; Listbox6.Clear; drueber:=path; h:=Length(path); if h>3 then begin repeat Dec(h); until (Path[h] = '\') or (h=1); if Path[h]='\' then drueber:=Copy(Path,1,h); end; if (drueber<>path) then begin ListItem := Listview3.Items.Add; Listitem.ImageIndex:=2; ListItem.Caption := '..'; ListItem.SubItems.Add(''); ListItem.SubItems.Add('DIR'); ListItem.SubItems.Add('');
end; if (FindFirst(Path + '*.*', faAnyFile, SR) = 0) then begin repeat if (SR.Attr <> faDirectory) then begin
Listbox6.Items.Add(SR.Name); end; until FindNext(SR) <> 0; FindClose(SR); end; for i:=0 to (Listbox6.Items.Count-1) do begin
size := -1; aFileName:=path+Listbox6.Items.strings[i]; if FindFirst(AFileName, faAnyFile, F) = 0 then begin try size := F.FindData.nFileSizeLow or (F.FindData.nFileSizeHigh shl 32); finally SysUtils.FindClose(F); end; end;
date1 := 0; hFile := Windows.FindFirstFile(pchar(aFileName), rStructur); if (INVALID_HANDLE_VALUE<>hFile) then begin Windows.FindClose(hFile); FileTimeToLocalFileTime(rStructur.ftLastAccessTime, rFileTime); FileTimeToDosDateTime(rFileTime, LongRec(dwLastAccess).Hi, LongRec(dwLastAccess).Lo); date1 := FileDateToDateTime(dwLastAccess); end;
erw:=''; e:=Length(Listbox6.Items.strings[i]); while e>-1 do begin if (Listbox6.Items.strings[i][e]<>'.') then erw:=Listbox6.Items.strings[i][e]+erw else begin punkt:=true; break; end; e:=e-1; end; if (punkt=true) then begin name:=''; for g:= 1 to e-1 do begin name:=name+Listbox6.Items.strings[i][g]; end; ListItem := Listview3.Items.Add; Listitem.ImageIndex:=1; ListItem.Caption := name; ListItem.SubItems.Add(erw); ListItem.SubItems.Add(inttostr(size)); ListItem.SubItems.Add(datetostr(date1)); punkt:=false; end else begin ListItem := Listview3.Items.Add; Listitem.ImageIndex:=0; ListItem.Caption := Listbox6.Items.Strings[i]; ListItem.SubItems.Add(''); ListItem.SubItems.Add('DIR'); ListItem.SubItems.Add(datetostr(date1)); end; end;
ListView3.AlphaSort;
end; |
Mit der FormCreate prozedur (also beim ersten Durchlauf) klappt das erstaunlich gut. Er zeigt sogar versteckte Dateien an. Alles ist supi.
Doppelklickt man nun auf einen Eintrag des Listviews entstehen die Probleme. Hier der Code:
Delphi-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26:
| procedure TForm1.ListView3DblClick(Sender: TObject); var i: integer; path, drueber: string; begin if (ListView3.SelCount<>-1) then begin if (ListView3.Selected.Caption='..') then begin path:=Label17.Caption; drueber:=path; i:=Length(Path); if i>3 then begin repeat Dec(i); until (Path[i] = '\') or (i=1); if Path[i]='\' then drueber:=Copy(Path,1,i); end; if (drueber<>path) then begin Verzeichnisbaumsteuern(drueber); end; end; end; end; |
So. Es ist vollkommen eigenartig

Scheinbar zufällig werden Dateien/Ordner weggelassen... Es ist einfach nur komisch. Und ich finde irgendwie keinen Fehler! Könnt ihr mir helfen? Habt ihr vielleicht die zündende Idee?
Ich danke schon mal im vorraus, weil ich weiß das ich mich auf euch verlassen kann!
MfG
DorJo