Autor Beitrag
Wolle92
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Fr 15.06.07 17:47 
Hallo... kann mir jemand helfen?
Ich hab ein Programm geschrieben, das dateien suchen soll, aber es findet keine...
Hab zur sicherheit mal das aktuelle verzeichnis anzeigen lassen, was zeigte, dass alles problemlos läuft...
Hier ist der entsprechende auszug aus dem Quellcode:
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:
procedure TForm1.SucheDir(ext: Str4; pfad: String);
var sr: TSearchRec;
    r: Integer;
begin
  r := FindFirst(pfad + '\*.*', faAnyFile, sr);
  while r = 0 do
  begin
    Label5.Caption := pfad + '\';
    if copy(sr.name, 1, 1) <> '.' then
    begin
      if (sr.Attr <> 0) and (faDirectory <> 0) then
        SucheDir(ext, pfad + '\' + sr.name)
      else
        if Copy(sr.name, Pos('.', sr.name), 5) = '.' + ext then
          ListBox1.Items.Add(pfad + '\' + sr.name);
    end;
    Application.ProcessMessages;
    r := FindNext(sr);
  end;
  FindClose(sr);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if Length(Edit1.Text) > 4 then
  begin
    ShowMessage('Bitte maximal 4 Zeichen als Dateiendung eigeben!');
    Exit;
  end;
  Button1.Enabled := false;
  Edit1.Enabled := false;
  DriveComboBox1.Enabled := false;
  ListBox1.Clear;
  SucheDir(Edit1.Text, DriveComboBox1.Drive + ':');
  Button1.Enabled := true;
  Edit1.Enabled := true;
  DriveComboBox1.Enabled := true;
  Label5.Caption := '';
end;

Ich hoffe, ihr könnt mir helfen


Moderiert von user profile iconChristian S.: Topic aus Delphi Language (Object-Pascal) / CLX verschoben am Fr 15.06.2007 um 19:04
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 15.06.07 17:51 
Moin und :welcome: im Forum!

Auf den ersten Blick würde ich sagen, hier ist der Fehler:
user profile iconWolle92 hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
procedure TForm1.SucheDir(ext: Str4; pfad: String);
var sr: TSearchRec;
    r: Integer;
begin
  r := FindFirst(pfad + '\*.*', faAnyFile, sr);
  while r = 0 do
  begin
    Label5.Caption := pfad + '\';
    if copy(sr.name, 1, 1) <> '.' then
    begin
      if ((sr.Attr and faDirectory) <> 0) then
        SucheDir(ext, pfad + '\' + sr.name)
      else
        if Copy(sr.name, Pos('.', sr.name), 5) = '.' + ext then
          ListBox1.Items.Add(pfad + '\' + sr.name);
    end;
    Application.ProcessMessages;
    r := FindNext(sr);
  end;
  FindClose(sr);
end;

cu
Narses

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

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Fr 15.06.07 18:03 
jau danke... aber was heißt die zeile überhaupt?
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 15.06.07 18:12 
Moin!

Damit prüfst du, ob das Verzeichnis-Bit in den Attributen gesetzt ist. ;)

cu
Narses

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

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Fr 15.06.07 19:06 
ok, danke...

Hab jetzt nen neues Problem bei einem Abbrechen-Button...
Damit die Schleife vorher nicht aufhört, muss der Wert von abort false sein...
Wenn ich dann die variable so definiert habe:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
...
private
{ private declarations }
abort: Boolean;
...

und ihr dann mit
ausblenden Delphi-Quelltext
1:
2:
3:
4:
...
initialization
abort := false;
end.

den wert false zugewiesen habe, kommt es in der Zeile "abort := false;" zu diesem Fehler:
Zitat:
[Error] Unit1.pas(108): Left side cannot be assigned to

Und den kann ich irgendwie nicht nachvollziehen...
Sinspin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1342
Erhaltene Danke: 121

Win 10
RIO, CE, Lazarus
BeitragVerfasst: Fr 15.06.07 19:37 
du brauchst nicht explizit angeben das abort false sein soll. das ist es automatisch. anders wäre es bei true.

_________________
Wir zerstören die Natur und Wälder der Erde. Wir töten wilde Tiere für Trophäen. Wir produzieren Lebewesen als Massenware um sie nach wenigen Monaten zu töten. Warum sollte unser aller Mutter, die Natur, nicht die gleichen Rechte haben?
Sinspin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1342
Erhaltene Danke: 121

Win 10
RIO, CE, Lazarus
BeitragVerfasst: Fr 15.06.07 19:46 
An deiner stelle würde ich,
ausblenden Delphi-Quelltext
1:
  if Copy(sr.name, Pos('.', sr.name), 5) = '.' + ext then					

durch:
ausblenden Delphi-Quelltext
1:
  if UpperCase(ExtractFileExt(sr.name)) = '.' + UpperCase(ext) then					

ersetzen.

Wobei es sich hier empfielt die Extension (ext) vorneweg einmal "groß" zu machen. Denn das kostet an dieser Stelle ordentlich Zeit.

_________________
Wir zerstören die Natur und Wälder der Erde. Wir töten wilde Tiere für Trophäen. Wir produzieren Lebewesen als Massenware um sie nach wenigen Monaten zu töten. Warum sollte unser aller Mutter, die Natur, nicht die gleichen Rechte haben?
Wolle92 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Fr 15.06.07 20:02 
ok, danke...
nächste Frage:
Wie kann ich so eine zweispaltige Liste machen, sodass in der ersten Spalte der Dateiname steht und in der zweiten spalte der Ort der Datei?
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 15.06.07 22:47 
Moin!

Forumsregel: nur eine Frage pro Thread! :mahn: Sonst gibt das Chaos... :? Mach bitte für die neue Frage auch einen neuen Thread auf. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.