Autor Beitrag
lkz633
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 136

WinXP, Suse Linux 8.2 (unter VMWare)
D7 Prof, K3 Prof
BeitragVerfasst: So 09.02.03 17:09 
Hi,

ich möchte einen Ordner löschen, jedoch muss dieser davor leer sein. Wie mache ich dies ? Hab mal gedacht, dass ich alle Dateinamen einer Stringliste übergebe, und dann die einzelnen Strings deletefile übergebe, nur wie bekomme ich die dateinamen in die Stringliste ?

Was gibts noch für Möglichkeiten ?

Herlichen Dank für eure Hilfe
lkz633
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: So 09.02.03 17:15 
wurde schon mehrfach diskutiert, Eine Forumsuche wäre nicht schlecht gewesen. Stichwort: SHFileOperation
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:
// Author: Rainer Kümmerle (webmaster@delphimania.de)

uses 
  ShellApi; 

function CopyDir(const fromDir, toDir: string): Boolean; 
var 
  fos: TSHFileOpStruct; 
begin 
  ZeroMemory(@fos, SizeOf(fos)); 
  with fos do 
  begin 
    wFunc  := FO_COPY; 
    fFlags := FOF_FILESONLY; 
    pFrom  := PChar(fromDir + #0); 
    pTo    := PChar(toDir) 
  end; 
  Result := (0 = ShFileOperation(fos)); 
end

function MoveDir(const fromDir, toDir: string): Boolean; 
var 
  fos: TSHFileOpStruct; 
begin 
  ZeroMemory(@fos, SizeOf(fos)); 
  with fos do 
  begin 
    wFunc  := FO_MOVE; 
    fFlags := FOF_FILESONLY; 
    pFrom  := PChar(fromDir + #0); 
    pTo    := PChar(toDir) 
  end; 
  Result := (0 = ShFileOperation(fos)); 
end

function DelDir(dir: string): Boolean; 
var 
  fos: TSHFileOpStruct; 
begin 
  ZeroMemory(@fos, SizeOf(fos)); 
  with fos do 
  begin 
    wFunc  := FO_DELETE; 
    fFlags := FOF_SILENT or FOF_NOCONFIRMATION; 
    pFrom  := PChar(dir + #0); 
  end; 
  Result := (0 = ShFileOperation(fos)); 
end;


Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
lkz633 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 136

WinXP, Suse Linux 8.2 (unter VMWare)
D7 Prof, K3 Prof
BeitragVerfasst: So 09.02.03 17:21 
Natürlich habe ich davor gesucht und auch den code gefunden, leider hat er nicht funktioniert

Gruss lkz633
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: So 09.02.03 19:25 
lkz633 hat folgendes geschrieben:
leider hat er nicht funktioniert

was klappt denn nicht?
bei mir funktionierts.

Mfg frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
lkz633 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 136

WinXP, Suse Linux 8.2 (unter VMWare)
D7 Prof, K3 Prof
BeitragVerfasst: So 09.02.03 19:36 
Tja, der Ordner wird einfach nicht gelöscht

Rückgabewert ist 0.

Gruss lkz633
lkz633 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 136

WinXP, Suse Linux 8.2 (unter VMWare)
D7 Prof, K3 Prof
BeitragVerfasst: Di 11.02.03 12:11 
Ich habe es jetzt mit findfirst gemacht, hab dazu noch ne frage, in euem thread

Danke für eure Hilfe
lkz633
MathiasSimmack
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Di 11.02.03 12:42 
SHFileOperation ist aber die einfachere Variante.

Zeig doch mal den Code, den du benutzt hast, oder wenn du ihn 1:1 übernommen hast, dann die Frage: bist du sicher, den korrekten Namen angegeben zu haben? Keine doppelten Backslashes, usw.?

Der Rückgabewert Null lässt eigentlich darauf schließen, dass der Aufruf erfolgreich war:
ausblenden Quelltext
1:
Result := (0 = ShFileOperation(fos));					

Vielleicht hast du auch versucht, einen Ordner zu löschen, den du nicht löschen darfst/kannst (mangels Rechten)?
lkz633 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 136

WinXP, Suse Linux 8.2 (unter VMWare)
D7 Prof, K3 Prof
BeitragVerfasst: Di 11.02.03 12:53 
Hi,

den Pfad habe ich mir anzeigen lassen, der stimmt, aber ich werd heut abend nochmal alles anschauen.

Den Ordner erstelle ch davor selber, also Berechtigung ist vorhanden.

Den code habe ich 1:1 übernommen :oops: :oops:

Gruss lkz633