Autor Beitrag
Nowo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 108



BeitragVerfasst: Do 24.04.08 19:32 
Hey ich komm hier einfach nicht weiter.

ausblenden volle Höhe 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:
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:
unit UnitSearch;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Menus, ComCtrls;

type
  TFormSearch = class(TForm)
    EditPath: TComboBox;
    Label1: TLabel;
    Label2: TLabel;
    EditFileName: TEdit;
    Edit2: TEdit;
    EditExtension: TComboBox;
    BtnSearch: TButton;
    BtnClear: TButton;
    FindList: TListView;
    procedure BtnSearchClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FormSearch: TFormSearch;

implementation
uses
UnitReveal;

{$R *.dfm}





procedure GetFilesInDirectory(Directory: String; const Mask: String;
                              List: TStrings;
                              WithSubDirs, ClearList: Boolean);

procedure ScanDir(const Directory: String);
var
  SR: TSearchRec;
begin
  if FindFirst(Directory + Mask, faAnyFile and not faDirectory, SR) = 0 then try
    repeat
      List.Add(Directory + SR.Name)
    until FindNext(SR) <> 0;
  finally
    FindClose(SR);
  end;

  if WithSubDirs then begin
    if FindFirst(Directory + '*.*', faAnyFile, SR) = 0 then try
      repeat
        if ((SR.attr and faDirectory) = faDirectory) and
           (SR.Name <> '.') and (SR.Name <> '..') then
          ScanDir(Directory + SR.Name + '\');
      until FindNext(SR) <> 0;
    finally
      FindClose(SR);
    end;
  end;
end;

begin
  List.BeginUpdate;
  try
    if ClearList then
      List.Clear;
    if Directory = '' then Exit;
    if Directory[Length(Directory)] <> '\' then
      Directory := Directory + '\';
    ScanDir(Directory);
  finally
    List.EndUpdate;
  end;
end;








procedure TFormSearch.BtnSearchClick(Sender: TObject);
var
  F: TSearchRec;
begin
  if FindFirst(EditFileName.text+'.'+EditExtension.text, faAnyFile, F) = 0 then try
    FindList.Items.Add do begin
      caption:= F.Name;
      SubItems.Add:=IntToStr(F.Size);

  finally
    FindClose(F);
  end;
end;

end.


Nach einem tutorial von hier:
www.delphi-treff.de/...rzeichnisse/tipp/76/

Also ich will die gefundenen dateien in ein ListView eintragen lassen.
(dazu mit subitems.add die größe)


Ist das möglich ?


Moderiert von user profile iconNarses: Topic aus Delphi Language (Object-Pascal) / CLX verschoben am Do 24.04.2008 um 21:52

_________________
Grüße Nowo
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 24.04.08 20:53 
Moin!

user profile iconNowo hat folgendes geschrieben:
Also ich will die gefundenen dateien in ein ListView eintragen lassen.
(dazu mit subitems.add die größe)

Ist das möglich ?
Ja. ;)

Wo ist das Problem? :nixweiss:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Nowo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 108



BeitragVerfasst: Fr 25.04.08 14:15 
Das problem ist das es nicht geht


hab überlegt es so zu machen:


ausblenden volle Höhe 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:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
Procedure FindFiles (aPath, aFindMask: String; aWithSub: Boolean; aResult: tStrings);
Var
  FindRec: tSearchRec;
Begin
  // Wenn die Stringliste nil ist oder aPath oder aFind nicht angegeben ist
  // dann raus
  If (aPath = '') or (aFindMask = '') or Not Assigned (aResult) Then
    Exit;

  // Wenn am Ende der Pfadangabe noch kein \ steht, dieses hinzufügen
  // (Oder die Funktion  IncludeTrailingPathDelimiter aus der Unit SysUtils.pas verwenden)
  If aPath[Length (aPath)] <> '\' Then
    aPath := aPath + '\';

  // Im aktuellen Verzeichnis nach der Datei suchen
  If FindFirst (aPath + aFindMask, faAnyFile, FindRec) = 0 Then
    Repeat
      If (FindRec.Name <> '.') and (FindRec.Name <> '..') Then
        // ...Ergebnis in die Stringlist einfügen
        aResult.Add (aPath + FindRec.Name);
    Until FindNext (FindRec) <> 0;

  FindClose (FindRec);

  // Wenn nicht in Unterverzeichnissen gesucht werden soll dann raus
  If Not aWithSub Then
    Exit;

  // In Unterverzeichnissen weiter suchen
  If FindFirst (aPath + '*.*', faAnyFile, FindRec) = 0 Then
    Repeat
      If (FindRec.Name <> '.') and (FindRec.Name <> '..') Then
        // Feststellen, ob es sich um ein Verzeichnis handelt
        If Boolean (FindRec.Attr and faDirectory) Then
          // Funktion erneut aufrufen, um Verzeichnis zu durchsuchen (Rekursion)
          FindFiles (aPath + FindRec.Name, aFindMask, aWithSub, aResult);
    Until FindNext (FindRec) <> 0;

   FindClose (FindRec);
End;



aufgerufen mit:

ausblenden Delphi-Quelltext
1:
FindFiles ('c:\windows', '*.txt', True, ListBox1.Items);					


ok aber wie komme ich jetzt das ganze in ein ListView, mit Dateiname / Größe und-oder Attribut ?

_________________
Grüße Nowo


Zuletzt bearbeitet von Nowo am Fr 25.04.08 14:59, insgesamt 1-mal bearbeitet
Hendi48
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 271



BeitragVerfasst: Fr 25.04.08 14:25 
Ich glaube du hast das with und end; vergessen!

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TFormSearch.BtnSearchClick(Sender: TObject);  
var  
  F: TSearchRec;  
begin  
  if FindFirst(EditFileName.text+'.'+EditExtension.text, faAnyFile, F) = 0 then 
  try  
    with FindList.Items.Add do 
    begin  
      caption:= F.Name;  
      SubItems.Add:=IntToStr(F.Size);  
    end;
  finally  
    FindClose(F);  
  end;  
end;
Nowo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 108



BeitragVerfasst: Fr 25.04.08 15:42 
geht trootzdem nich :- /

_________________
Grüße Nowo
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Fr 25.04.08 15:54 
Moin!

Was soll das denn nun werden? Willst du das Ergebnis von FindFiles() in ein Listview eintragen oder willst du die Prozedur so modifizieren, dass sie ein TListView befüllt, statt TStrings?! :nixweiss:

Deine Aussagen/Code sind etwas konfus... :gruebel:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Nowo Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 108



BeitragVerfasst: Fr 25.04.08 17:46 
Sie soll ein TListView befüllen ja.
Mit eigenen angaben. Sollte am ende so ähnlich wie die detail ansicht des explorers aussehen :- /

_________________
Grüße Nowo
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Fr 25.04.08 17:54 
Ich frage mich aber immer noch wo dabei eigentlich das Problem liegt? Ich meine, weißt du nicht, wie du eine ListView benutzt oder was sonst? Denn letztendlich musst du ja nur statt einfach mit aResult.Add(... nur den Dateinamen und Pfad zu der Ergebnisliste hinzuzufügen die Daten in die ListView tun.

Weißt du nicht, wie du eine ListView benutzt? Oder hast du den Quelltext nicht verstanden und kannst den deshalb nicht ändern?