Autor Beitrag
Biarchiv
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 688



BeitragVerfasst: So 17.07.05 09:09 
Hey,

wolte folgendes machen.
Eine Editbox in der man existierende Verzeichnisse reinschreiben kann...
c:\test;c:\winnt;\c:\....

Okay nun soll man aber alle verzeichnisse einzeln rauslessen können.
Aber wie wenn alle durch ";" getrennt sind.
Und es soll auch auf existenz der Verzeichnisse geprüft werden.

Vielen Dank...
Harry M.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 754

Win 2000, XP
D2005
BeitragVerfasst: So 17.07.05 09:58 
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:
function DirExists(s: string): Boolean;
 var i: Integer;
 begin
  i := GetFileAttributes(PChar(s));
  Result := (i <> -1) and (FILE_ATTRIBUTE_DIRECTORY and i <> 0)
 end;

procedure TForm1.Button1Click(Sender: TObject);
var
  I: Integer;
  DIR: String;
begin
  DIR := '';
  if  Edit1.Text[Length(Edit1.Text)] <> ';' then Edit1.Text := Edit1.Text+';';  //ggf letzten seperator setzten !!

  for I := 0 to Length(Edit1.Text) do
    if (Edit1.Text[I] = ';') then begin
      if DirExists(DIR) then showmessage('Verzeichnis '+DIR+' existiert')
        else showmessage ('Verzeichnis '+DIR+' existiert nicht');
      DIR := '';
      end else DIR := Trim(DIR+Edit1.Text[I]);
end;

_________________
Gruß Harry
Et spes me per dies sine te ducat et amor me ferat, si dolor spem tollit.
Sprint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 849



BeitragVerfasst: So 17.07.05 10:02 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
const
  MSG = 'Verzeichnis "%s" existiert nicht.';
var
  I: Integer;
begin

  with TStringList.Create do
    try
      Delimiter := ';';
      DelimitedText := Edit1.Text;
      for I := 0 to Count - 1 do
        if not DirectoryExists(Strings[I]) then
          ShowMessage(Format(MSG, [Strings[I]]));
    finally
      Free;
    end;

end;

_________________
Ciao, Sprint.
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 17.07.05 23:30 
Das ';' ist aber auch in Dateinamen zulässig!