Hallo,
das ist mein erster Thread hier und ich werde versuchen alle Regelen zu beachten.
Ich habe bereits viel gelesen ind diesem Forum und einiges über Delphi gelernt auch habe ich über mein Probelm bereits mehrere Postings gefunden aber ich bin nicht wiklich auch einen grünen Ast gekommen darum bitte ich um eure Hilfe.
Möchte noch anfügen das ist mein erstes Programm, habe erst gestern begonnen mit Delphi.
Problemstellung:
Ich lese mit einer rekursiven Funktion das Temporäre Verzeichnis von Windows aus, alle gefundene Dirs und Files werden in eine ListBox geschrieben, das klappt auch soweit.
Nun möchte ich alle markierten einträge in der ListBox von der Festplatte löschen.
Benutzen möchte ich die DeleteFiles Funktion von Delphi, leider komme ich nicht dahinter wie ich die Selektierten Items mit der Forschleife durchspringt.
Gelöscht sollen nur die Selektierten Files werden.
Hier mein derzeitiger Code:
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:
| function GetTempDir: String; begin result := SysUtils.GetEnvironmentVariable('temp'); end;
procedure TMainform.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 - faDirectory, SR) = 0 then try repeat List.Add(Directory + SR.Name); inc(filecount); mainform.filelabel.Caption:= inttostr(filecount); until FindNext(SR) <> 0; finally FindClose(SR); end;
application.ProcessMessages;
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 begin ScanDir(Directory + SR.Name + '\'); inc(dircount); mainform.dirlabel.Caption:= inttostr(dircount); end; 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 Tmainform.Button1Click(Sender: TObject); begin dircount:= 0; filecount:= 0; GetFilesInDirectory(edit1.text, edit2.text, Listbox1.Items, true, false); end;
procedure Tmainform.Button2Click(Sender: TObject); var i: integer; max: integer; begin max := ListBox1.Items.Count; ShowMessage('Anzahl der zu löschenden Files' + inttostr(max)); for i := ListBox1.Items.Count-1 downto 0 do begin if ListBox1.Selected[i] then ShowMessage(inttostr(Listbox1.ItemIndex)); end; end;
procedure Tmainform.Button3Click(Sender: TObject); begin ListBox1.Clear; filecount := 0; mainform.filelabel.Caption:= '-'; dircount := 0; mainform.dirlabel.Caption:= '-'; Edit1.Text := GetTempDir; end;
procedure Tmainform.FormCreate(Sender: TObject); begin Edit1.Text := GetTempDir; end;
end. |
Ich hoffe jemand hat Zeit mir dabei zu helfen auch wenn das schon des öffterne gefragt wurde.
Vielen Danke