Autor Beitrag
Jakob Schöttl
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 929
Erhaltene Danke: 1


Delphi 7 Professional
BeitragVerfasst: Do 29.06.06 15:40 
Hallo,
gibt es eine API-Funktion, mit der ich Dateien oder Ordner löschen kann, genauso, wie im Windows Explorer, also mit StatusAnzeige, Abbrechen und so...

Ich wäre froh, wenn ihr mir helfen könntet


Zuletzt bearbeitet von Jakob Schöttl am Do 06.07.06 15:16, insgesamt 2-mal bearbeitet
crowley
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 406

Win XP, Win Vista, Mandriva, Ubuntu
Delphi 4-8, Delphi 2006, Delphi 2007
BeitragVerfasst: Fr 30.06.06 06:54 
schau dir mal in der Hilfe ShFileOperation und TSHFileOpStruct an... da stehen einige Infos un Einstellungen noch dabei... der Code unten sollte Verzeichnisse und Dateien mit Fortschrittanzeige löschen...

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
function DelDir(Dir : String) : Boolean;
var
 FileOption : TSHFileOpStruct;
begin
 ZeroMemory(@FileOption,SizeOf(FileOption));
 with FileOption do
 begin
   wFunc := FO_DELETE;
   fFlags := FOF_NOCONFIRMATION;
   pFrom := PChar(Dir + #0);
 end;
 Result := (ShFileOperation(FileOption) = 0);
end;


Viel Erfolg
C.
Jakob Schöttl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 929
Erhaltene Danke: 1


Delphi 7 Professional
BeitragVerfasst: Fr 30.06.06 07:08 
Danke Crowley!

In der Hilfe steht zu den beiden schlüsselwörtern bei Delphi7 leider nichts, und auch TShFileOpStruct ist undefinierter Bezeichner. Welche Units hast du denn eingebunden, außer den Standards? EDIT: ShellAPI
Hat sich erübrigt: Oder gibt es diese Opbjekte erst ab einer höheren Delphi Version?

Danke, das war glaub ich was ich gesucht hab!


Zuletzt bearbeitet von Jakob Schöttl am Fr 30.06.06 07:11, insgesamt 1-mal bearbeitet
crowley
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 406

Win XP, Win Vista, Mandriva, Ubuntu
Delphi 4-8, Delphi 2006, Delphi 2007
BeitragVerfasst: Fr 30.06.06 07:10 
hab die schon bei Delphi 4 und Delphi 5 genutzt (glaub ich zumindest)...

schau mal nicht in der Delphi Hilfe sondern unter Hilfe > Windows SDK nach

benötigst in der uses Klausel noch die Unit ShellAPI
Jakob Schöttl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 929
Erhaltene Danke: 1


Delphi 7 Professional
BeitragVerfasst: Fr 30.06.06 07:15 
Aja, noch ne kleine frage zum QuellCode: Wieso PChar(dir + #0) dieses + #0? Ich dachte das wäre kein Leerzeichen, sondern ein NullChar.
crowley
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 406

Win XP, Win Vista, Mandriva, Ubuntu
Delphi 4-8, Delphi 2006, Delphi 2007
BeitragVerfasst: Fr 30.06.06 07:19 
ist auch kein Leerzeichen ;)

also pFrom erwartet einen PChar-Wert... PChars müssen immer auf ein #0 Zeichen Enden, ansonsten wird im Speicher immer weiter gesucht, bis ein solches gefunden wird ;)

mit Dir übergibst du einen String und wandelst ihn in einen PChar um... NORMALERWEISE endet ein Delphi-String schon auf ein #0 Zeichen... da ich - ich weiss nicht mehr in welchem Kontext - böse Probleme hatte, hänge ich hier bewusst noch ein #0 Zeichen vor der Umwandlung an den String hinten dran ;)
Jakob Schöttl Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 929
Erhaltene Danke: 1


Delphi 7 Professional
BeitragVerfasst: Fr 30.06.06 12:29 
aja, danke

Also für alle, die mal wieder nach
Datei-Operationen mit API:
Dateien löschen, kopieren, umbenennen, verschieben

suchen!

Stichwort: TSHFileOpStruct, SHFileOperation

Praktischer Link:
www.delphipraxis.net...ight=tshfileopstruct