Autor Beitrag
Maisinator
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 167

Win XP HE SP3, Win Vista HP SP2
Delphi ;-)
BeitragVerfasst: Mi 11.02.09 18:21 
cool danke!!!
Maisinator
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 167

Win XP HE SP3, Win Vista HP SP2
Delphi ;-)
BeitragVerfasst: Mi 11.02.09 20:15 
habs ausprobiert. was muss ich denn noch dazu schreiben, damit das prüft, ob die datei schon besteht und nicht einfach eine neue erstellt, auch wenn die alte noch besteht?
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 11.02.09 20:27 
Dafür gibt es FileExists. ;-)
Chemiker
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 194
Erhaltene Danke: 14

XP, Vista 32 Bit, Vista 64 Bit, Win 7 64 Bit, Win 10, Win 11
BDS 2006, RAD Studio 2009+C++, Delphi 13, VS 2010 Prof.
BeitragVerfasst: Mi 11.02.09 23:04 
Hallo Maisinator,

man kann sich auch eine kleine Klasse schreiben und die das Anlegen und Prüfen übernimmt.

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:
49:
50:
51:
52:
53:
54:
55:
56:
type
  TOrdner= Class(TObject)
  private
    FOrdnerName: TFileName;                             // PathName
    function GetOrdnerVorhanden: Boolean;
    function GetOrdnerName: TFileName;
    procedure SetOrdnerName(const Value: TFileName);
    procedure OrdnerAnlegen;
  public
    Constructor Create(aOrdnerAnlegen: Boolean; aOrdnerName: TFileName);
    destructor Destroy; override;

    property OrdnerVorhanden: Boolean Read GetOrdnerVorhanden;
    property OrdnerName: TFileName Read GetOrdnerName Write SetOrdnerName;
  End;

implementation

{ TOrdner }

constructor TOrdner.Create(aOrdnerAnlegen: Boolean; aOrdnerName: TFileName);
begin
  inherited Create;
  if aOrdnerAnlegen then
  begin
    FOrdnerName:= aOrdnerName;
    OrdnerAnlegen
  end;
end;

destructor TOrdner.Destroy;
begin
  inherited;
end;

function TOrdner.GetOrdnerName: TFileName;
begin
  Result:= FOrdnerName;
end;

function TOrdner.GetOrdnerVorhanden: Boolean;
begin
  Result:= DirectoryExists(FOrdnerName);
end;

procedure TOrdner.OrdnerAnlegen;
begin
  if not ForceDirectories(FOrdnerName) then
  begin
    if not CreateDir(FOrdnerName) then
    begin
      raise Exception.Create('Der Ordner '+FOrdnerName+
                               ' wurde nicht angelegt');
      end;
  end;
end;

Das Ganze solle selbsterklärend sein.


Bis bald Chemiker