Autor Beitrag
cromos
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 219


Delphi 7
BeitragVerfasst: Do 28.08.03 18:21 
Hallo,

ich möchte alle Dateien in einem bestimmten Verzeichnis löschen.
habe dazu vollgenden Code 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:
22:
23:
24:
25:
26:
27:
28:
procedure TForm8.SpeedButton3Click(Sender: TObject);
var res : integer;
var knopf : Integer;
var ProgrammOrdner : String;
ds: TSearchRec;
begin
ProgrammOrdner:=ExtractFilePath(application.ExeName);
knopf :=Application.MessageBox('Soll das ausgewählte Paket wirklich gelöscht werden?!','Frage',MB_YESNO);
   If knopf = idyes then
      begin
          //Paket Löschen

          res := FindFirst(ProgrammOrdner + 'data\' + lblAuswahl.Caption ,faAnyFile,ds);
          while(res =0do
              begin
                //löschen
                DeleteFile(ds.name);
          res := FindNext(ds);
              end;
              FindClose(ds);


      end
   else
      exit;


end;


hLeider löscht er nicht. Er macht gar nix. Auch keinen Fehler.
Der Pfad ist eigendlich richtig übergeben.

Gruss
Cromos
barfuesser
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 324



BeitragVerfasst: Do 28.08.03 18:27 
Hi,

kann es sein, daß in ds.name nur der Dateiname ohne Pfadangabe steht? Auf jeden Fall solltest Du einmal überprüfen, was DeleteFile zurückgibt.

barfuesser
kongreddgrass
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 238

Win 98, Win 2000, Win Xp Prof.,Linux 8.2 Prof
Delphi 6
BeitragVerfasst: Do 28.08.03 18:42 
Wieso benutzt du für das kein FileListBox und einen Lösch-Button

Hiermal der Code für den Button im DragDrop-Ereignis

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.Button1.DragDrop(Sender: TObject);//oder BitBtn
begin
if MessageLG('Datei'+FileListBox1.Filename+' wirklich löschen?',
mtConfirmation,
[mbYes,mbNo],
0)=mrYes then
if DeleteFile(FileListBox1.Filename) then
FileListBox1.Update


Ist doch auch sone Lösung

_________________
o.o
cromos Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 219


Delphi 7
BeitragVerfasst: Do 28.08.03 19:27 
Zitat:

Wieso benutzt du für das kein FileListBox und einen Lösch-Button


Weil ich auf dieser Form keine FileListBox haben möchte :wink: :)
cromos Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 219


Delphi 7
BeitragVerfasst: Do 28.08.03 19:35 
Titel: got it
Hallo,

hab den Fehler selber gefunden.

So ist die Zeile richtig:

ausblenden Delphi-Quelltext
1:
 res := FindFirst(ProgrammOrdner + 'data\' + lblAuswahl.Caption + '\*.*' ,faAnyFile,ds);					
kongreddgrass
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 238

Win 98, Win 2000, Win Xp Prof.,Linux 8.2 Prof
Delphi 6
BeitragVerfasst: Do 28.08.03 19:37 
Ich denke, jetzt müsstest du mal Happy sein. Herzlichen Glückwunsch

Gruß
Mike

_________________
o.o